简体   繁体   中英

Android HTTPPost and HTTPResponse error

I'm working on an app and having this problem. I'm using PHP as back end server and JSON as data transfer technology. But problem is that, Http POST and RESPONSE are not working. Http GET is working and user is being logged in but no response is getting back and POST also not working.

Please help me if you understand the problem.

    // Making HTTP request
    try {
        HttpParams httpParameters = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(httpParameters, timeOut);                                   HttpConnectionParams.setSoTimeout(httpParameters, timeOut);                                                                       
        HttpClient httpClient = new DefaultHttpClient(httpParameters);
        HttpEntity httpEntity = null;
        HttpPost httpPost = new HttpPost(url);
        httpPost.setEntity(new UrlEncodedFormEntity(params));
        HttpResponse httpResponse = httpClient.execute(httpPost);
        httpEntity = httpResponse.getEntity();

}

try like this:

HttpClient client = new DefaultHttpClient();
HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000); //Timeout Limit
HttpResponse response;

    try { 
       URI url = new URI("xxxxxxxxxxxxxxxxxxxxxx");
       HttpPost post = new HttpPost(url);
       JSONObject json = new JSONObject();
       json.put("x",x);
       json.put("y", y);        

       StringEntity se = new StringEntity(holder.toString());
       post.setEntity(se);
       response = client.execute(post);

       if(response!=null){
           InputStream in = response.getEntity().getContent(); //Get the data in the entity
           in.close();
        }
    } catch(Exception e) {
      e.printStackTrace();
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM