2017-05-21 42 views
-1

我正在使用此网址发送reqeust通过凌空:“http://136.243.146.41:8443/api/GetMainCategories”。 这里是我的代码:发送用户名和密码通过帖子请求凌乱在Android

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的”。我改变了网址 “tarkhinehapp/API/GetMainCategories” 但我得到另一个错误“com.android.volley.ServerError”

+0

发布您的网址在浏览器中工作,并检查其工作是否正常 – sasikumar

回答

0

我用凌空LIB连接到服务器并发送用户名和URL中的下面通过查询字符串传递:

 MyVolleyStringRequest mainmenureq=new MyVolleyStringRequest(Request.Method.GET, G.urlBase+"MainCategoriesApi?username="+"username"+"&"+"key="+"pass",new MyListener(this)); 

凌空使我的工作那么容易!

0

你检查了服务器日志吗?

相关问题