0

我正在开发一个应用程序并遇到此问题。我使用 PHP 作为后端服务器,使用 JSON 作为数据传输技术。但问题是,Http POST 和 RESPONSE 不起作用。Http GET 正在工作,用户正在登录,但没有回复,POST 也无法正常工作。

如果您理解问题,请帮助我。

    // 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();

}

4

1 回答 1

0

试试这样:

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();
    }
于 2013-10-25T15:05:13.490 回答