我正在使用此网址通过排球发送帖子请求:“http://136.243.146.41:8443/api/GetMainCategories”。 这是我的代码:
void MakePostRequest() {
StringRequest postRequest = new StringRequest(Request.Method.POST, mainmenurl,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonResponse = new JSONObject("{response}");
//makemainmenulist();
Toast.makeText(Cofeelist.this,"success!--->>>>"+response, Toast.LENGTH_LONG).show();
Log.i("sucsses!.....",response);
// value1= jsonResponse.getString("Your ID1");
// value2= jsonResponse.getString("Your ID2");
} catch (JSONException e) {
e.printStackTrace();
Toast.makeText(Cofeelist.this,"error1!--->>>>"+e, Toast.LENGTH_LONG).show();
Log.i("Error1!.....",e+"");
// banner_id = null;
// full_id = null;
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
Toast.makeText(Cofeelist.this,"error2!--->>>>"+error, Toast.LENGTH_LONG).show();
Log.i("error2!.....",error+"");
// value1= null;
// value2= null;
}
}
) {
// here is params will add to your url using post method
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<>();
params.put("username", "pourya");
params.put("key", "54a65sdf4a35s4d");
return params;
}
};
Volley.newRequestQueue(this).add(postRequest);
}
但我得到了这个错误:“com.android.volley.NoConnectionError:java.io.EOFException”.i将网址更改为“tarkhinehapp / api / GetMainCategories”,但我收到了另一个错误“com.android.volley.ServerError “
答案 0 :(得分:0)
您检查过服务器日志吗?
答案 1 :(得分:0)
我使用volley lib连接到服务器并发送用户名并通过url中的querystring传递,如下所示:
MyVolleyStringRequest mainmenureq=new MyVolleyStringRequest(Request.Method.GET, G.urlBase+"MainCategoriesApi?username="+"username"+"&"+"key="+"pass",new MyListener(this));
凌空让我的工作变得如此简单!