public static string Sendhttprequestbypost (final String address,string encode,matterreflectdto dto) {
String result = "";
Defaulthttpclient defaulthttpclient = new Defaulthttpclient ();
HttpPost HttpPost = new HttpPost (address);
String jsonstring = dto.tostring ();
try {
stringentity stringentity = new Stringentity (new Gsonbuilder (). Create (). ToJson (DTO));
System.out.println (Stringentity.tostring ());
httppost.setentity (stringentity);
Httppost.setheader ("Accept", "Application/json");
Httppost.setheader ("Content-type", "Application/json");
Httppost.setheader ("accept-encoding", "gzip");
HttpResponse HttpResponse = Defaulthttpclient.execute (HttpPost);
SYSTEM.OUT.PRINTLN ("Request Result:" +httpresponse.getstatusline (). Getstatuscode ());
int code = Httpresponse.getstatusline (). Getstatuscode ();
if (code ==200) {
InputStream is = Httpresponse.getentity (). getcontent ();
result = "true";
}
} catch (Unsupportedencodingexception e) {
E.printstacktrace ();
} catch (Clientprotocolexception e) {
E.printstacktrace ();
} catch (IOException e) {
E.printstacktrace ();
}
return result;
}
The server side is using. NET for the time being, and it is important to note that it is not passed by parameters.
This article is from the "Five Piglets" blog, please be sure to keep this source http://wuxiaozhu.blog.51cto.com/7942143/1765405
Android Access Webapi, passing JSON