Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class RequestTask extends AsyncTask<String, String, String>{
- @Override
- protected String doInBackground(String... uri) {
- HttpClient httpclient = new DefaultHttpClient();
- HttpResponse response;
- String responseString = null;
- try {
- response = httpclient.execute(new HttpGet(uri[0]));
- StatusLine statusLine = response.getStatusLine();
- if(statusLine.getStatusCode() == HttpStatus.SC_OK){
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- response.getEntity().writeTo(out);
- responseString = out.toString();
- out.close();
- } else{
- //Closes the connection.
- response.getEntity().getContent().close();
- throw new IOException(statusLine.getReasonPhrase());
- }
- } catch (ClientProtocolException e) {
- //TODO Handle problems..
- } catch (IOException e) {
- //TODO Handle problems..
- }
- return responseString;
- }
- @Override
- protected void onPostExecute(String result) {
- super.onPostExecute(result);
- ShowMsg(thisone,result);
- }
- }
- new RequestTask().execute("http://www.stackoverflow.com");
- new RequestTask().execute("http://127.0.0.1");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement