Android webrequest simple solution -
I want to connect to a web-server (a page) through a simple URL which is already in a parameter Wanted to send, such as: www.web-site.com/action.php/userid/42/secondpara/23/ and then get page content that is generated by site (will not be a simple OK / no morp'd) . How do I manage to do this?
try it:
public Static zero connect (string url) {http client httpclient = new DefaultHttpClient (); // Create a Request Object HttpGet httpget = new HttpGet (url); // Request to execute HTTP response response; Try {feedback = httpclient.execute (httpget); // Check the response status Log.i ("Praeda", response.getStatusLine (). ToString ()); // Response unit HttpEntity unit hold = response.getEntity (); // If the response does not attach to an entity, then there is no need for // to worry about the release of the connection (unit! = Zero) {// Read a simple JSON response InputStream instream = entity.getContent (); String result = convertstreamstustring (instream); // Now you have the instream.close () representing the string of the HTML request; }} Hold (Exception E) {}} Personal Static String ConvertStreamToString (InputStream) {/ * * To change InputStream to string we use BufferedReader.readLine () * method. We repeat the buffed reader returns to the empty which means * there is no data to read and each row will be linked to stringbuilder * and it will return as a string. * / BufferedReader Reader = New BufferedReader (New InputStreamReader); Stringbilder sb = new stringbiller (); String line = null; Try {{line = reader. Readline ()) = = null {sb.append (line + "\ n");}} grip (IOException e) {e.printStackTrace ();} Finally {try { Is.close () is;} hold (IOException e) {e.printStackTrace ();}} return sb.toString ();}
Comments
Post a Comment