Monday, May 5, 2014

httpclient () post a wonderful question!


 private String connServerForResult (String path, String contents) {
/ / TODO Auto-generated method stub
HttpClient client = new DefaultHttpClient ();
String json = null;

try {
/ / Destination address
HttpPost request = new HttpPost (path);
/ / Constructor string data
StringEntity entity = new StringEntity (contents);
/ / Set the type
entity.setContentType ("application / x-www-form-urlencoded");

entity.setContentEncoding (new BasicHeader (HTTP.CONTENT_ENCODING, HTTP.UTF_8));
Data
/ / Set requestrequest.setEntity (entity);
/ / Execute
HttpResponse response = client.execute (request);
HttpEntity httpentity = response.getEntity ();
/ / Result
json = EntityUtils.toString (httpentity);
System.out.println ("account" + json);
} Catch (Exception e) {
e.printStackTrace ();
}
return json;
}
};

This is the code! When tested post no problem! But the real address changed after the server can not obtain the data I post up! Can return an error message! This is what ah? (Server code is the same)
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Determine under your server address is correct, see what type of error return. Whether the server receives a request
Reply:
respones can see the code, and a code to see what is wrong, and then re-check the correctness of combining url
Reply:
Themselves! Is the problem server address!

No comments:

Post a Comment