gpt4 book ai didi

android - 意外的响应代码 405 com.android.volley.ServerError

转载 作者:行者123 更新时间:2023-11-30 00:53:08 25 4
gpt4 key购买 nike

我想将表单数据发送到服务器。我为此使用了 volly 库,但是下面的代码显示了以下错误。

Unexpected response code 405 com.android.volley.ServerError

我的代码是:

public class Wow extends AppCompatActivity {

private EditText editTextName;
private EditText editTextLocation;
private EditText editTextEmail;
private EditText editTextWebsite;
private Button buttonRegister;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.data_sent_form);

editTextName = (EditText) findViewById(R.id.editTextname);
editTextLocation = (EditText) findViewById(R.id.editTextlocation);
editTextEmail = (EditText) findViewById(R.id.editTextEmail);
editTextWebsite = (EditText) findViewById(R.id.editTextwebsite);
buttonRegister = (Button) findViewById(R.id.buttonRegister);

buttonRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
suman();
}
});
}

void suman() {

final String name = editTextName.getText().toString().trim();
final String location = editTextLocation.getText().toString().trim();
final String email = editTextEmail.getText().toString().trim();
final String website = editTextWebsite.getText().toString().trim();

try
{
RequestQueue requestQueue = Volley.newRequestQueue(this);
String URL = "http://myeducationhunt.com/schools/create";
JSONObject jsonBody = new JSONObject();
jsonBody.put("name", name);

final String mRequestBody = jsonBody.toString();

StringRequest stringRequest = new StringRequest(Request.Method.POST, URL, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.i("VOLLEY", response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("VOLLEY", error.toString());
}
}) {


@Override
public byte[] getBody() throws AuthFailureError {
try {
return mRequestBody == null ? null : mRequestBody.getBytes("utf-8");
} catch (UnsupportedEncodingException uee) {
VolleyLog.wtf("Unsupported Encoding while trying to get the bytes of %s using %s", mRequestBody, "utf-8");
return null;
}
}
};
requestQueue.add(stringRequest);
} catch (JSONException e) {
e.printStackTrace();
}
}
}

**logcat 看起来像这样**

11-15 12:49:13.648 17579-19711/com.user.retrofit E/Volley: [254] BasicNetwork.performRequest: Unexpected response code 405 for http://myeducationhunt.com/schools/create
11-15 12:49:13.649 17579-17579/com.user.retrofit E/VOLLEY: com.android.volley.ServerError

最佳答案

通过更改请求 GET FROM POST MY ERROR REMOVES .Thankyou 的宝贵答复

关于android - 意外的响应代码 405 com.android.volley.ServerError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40603996/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com