Android Access Webapi, passing JSON

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.