Android via HTTP POST to ask ASP.

Source: Internet
Author: User
Tags convert net http post

Looking at a lot of video on the web about how Android uses HTTP POST or get access to Web pages and get data.

I also copied a copy to test. and through C #. NET to build a simple backstage, but found that when the transfer, according to the online way to do not get the corresponding results.

Here's my request for a sticker.

http://bbs.csdn.net/topics/390814679

A long time no one to answer this question, we are not expected to use ASP.

After repeated testing of the phone-side code. found that in fact, the background of the ASP, in fact, can directly parse the URL with the parameters, do not need to be introduced online method to achieve

Here is the main part of the Intercept test code:

Button Trigger:

<span style= "white-space:pre" ></span>final button btn2 = (Button) Findviewbyid (R.id.button2); Btn2.setonclicklistener (New Onclicklistener () {public void OnClick (View v) {progressdialog = Progressdialog.show ( Mainactivity.this, "Loading ...", "Please wait ...", true, false);//New Thread () {@Overridepublic void Run () {//The method that takes time to calculate the try {Str ing str = posturl ("http://aspspider.info/lanjackg2003/Default.aspx?name=lan120576664&psw=456"); Textviewhttpres.settext (Str.tostring ());} catch (Exception e) {///Todo:handle exception}//sends a message to handler handler.sendemptymessage (0);}}. Start ();}});
Getcode for Web page data:

public string PostURL (string url) {InputStream is = null;        String result = "";            try{HttpClient HttpClient = new Defaulthttpclient ();            HttpPost HttpPost = new HttpPost (URL);            HttpResponse response = Httpclient.execute (HttpPost);            httpentity entity = response.getentity ();        is = Entity.getcontent (); }catch (Exception e) {return "Fail to establish HTTP connection!"        +e.tostring ();            } try{BufferedReader reader = new BufferedReader (new InputStreamReader (IS, "utf-8"));            StringBuilder sb = new StringBuilder ();            String line = null;            while (line = Reader.readline ())! = null) {Sb.append (line + "\ n");            } is.close ();            Result=sb.tostring ();        LOG.V (Log_tag,result.tostring ());        }catch (Exception e) {return "Fail to convert net stream!";    } return result; }

Mobile Display

PC-side Display display:


P C is consistent with the results shown on the phone.


Android via HTTP POST to ask ASP.

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.