Android uses post submission

Source: Internet
Author: User

1, the use of post to submit the need not to pass the number of references written in the URL, be sure to use Basicnamevaluepair this class to complete

Create a URL that I want to send a similar get method----------http://localhost/app/camera.php?

Opt=discovery

Do not pass the following parameters directly to the past when submitting using post. Be sure to use the following method

HttpClient client = new Defaulthttpclient (); HttpPost post = new HttpPost ("http://localhost/app/camera.php");//Set HTTP POST request parameters must be Namevaluepair object list< namevaluepair> params = new arraylist<namevaluepair> ();p Arams.add (new Basicnamevaluepair ("opt", "discovery" ); try {post.setentity (new urlencodedformentity (params, HTTP). Utf_8)); HttpResponse response = Client.execute (POST), if (Response.getstatusline (). Getstatuscode () = = () {String string = Entityutils.tostring (Response.getentity ()); System.out.println (string);//toast.maketext (Mainactivity.this, Response.getstatusline (). Getstatuscode (), 1). Show ();} else {//toast.maketext (mainactivity.this, Response.getstatusline (). Getstatuscode (), 1). Show ();}} catch (Clientprotocolexception e) {//Todo auto-generated catch Blocke.printstacktrace ();} catch (IOException e) {//TODO Auto-generated catch Blocke.printstacktrace ();}


Android uses post submission

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.