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.