Okay, well, I'm having an error executing a url via asynctask. When I am logged in everything looks good, if I disconnect from the internet the application hangs when clicking.
My code is:
String mylinkupdate = "http://www.meusite.com.php?id=" + mList.get(getAdapterPosition()).getId();
GetXMLTask tasku = new GetXMLTask();
tasku.execute(mylinkupdate);
function:
private class GetXMLTask extends AsyncTask<String, Void, String> {
#Override
protected String doInBackground(String... urls) {
String output = null;
for (String url : urls) {
output = getOutputFromUrl(url);
}
return output;
}
private String getOutputFromUrl(String url) {
StringBuffer output = new StringBuffer("");
try {
InputStream stream = getHttpConnection(url);
if (stream != null) {
stream.close();
}
BufferedReader buffer = new BufferedReader(
new InputStreamReader(stream));
String s = "";
while ((s = buffer.readLine()) != null)
output.append(s);
} catch(IOException e1){
e1.printStackTrace();
}
return output.toString();
}
// Makes HttpURLConnection and returns InputStream
private InputStream getHttpConnection(String urlString)
throws IOException {
InputStream stream = null;
URL url = new URL(urlString);
URLConnection connection = url.openConnection();
try {
HttpURLConnection httpConnection = (HttpURLConnection) connection;
httpConnection.setRequestMethod("GET");
httpConnection.connect();
if (httpConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {
stream = httpConnection.getInputStream();
}
} catch (Exception ex) {
ex.printStackTrace();
}
return stream;
}
#Override
protected void onPostExecute(String output) {
// Toast.makeText(mContext,output,Toast.LENGTH_LONG).show();
}
}
logcat:
07-15 14:49:44.649 1806-3467/app.meuapp E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #7
Process: app.meuapp, PID: 1806
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:318)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:762)
Caused by: java.lang.NullPointerException
at java.io.Reader.(Reader.java:78)
at java.io.InputStreamReader.(InputStreamReader.java:72)
at app.com.asnzapgrupos.meuzapzap.adapters.CarAdapter$GetXMLTask.getOutputFromUrl(CarAdapter.java:981)
at app.com.asnzapgrupos.meuzapzap.adapters.CarAdapter$GetXMLTask.doInBackground(CarAdapter.java:969)
at app.com.asnzapgrupos.meuzapzap.adapters.CarAdapter$GetXMLTask.doInBackground(CarAdapter.java:964)
at android.os.AsyncTask$2.call(AsyncTask.java:304)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:762)
thanks
Related
So I am having some problems with getting this code to work, I found some of this code online but it won't work. I have tried adjusting some code but no matter what I am doing, the app just crashes with an error. I have been trying to get this to work for a few days now with hours of googling and watching YouTube tutorials and I cannot seem to get this to work.
Can someone shed some light on what I am doing wrong here?
CODE:
public class fetchJSON extends AsyncTask<Void, Void, String> {
#Override
protected String doInBackground(Void... params) {
HttpURLConnection urlConnection = null;
BufferedReader reader = null;
URL url;
try {
url = new URL("www.link.to.json");
urlConnection.setRequestMethod("GET"); //Your method here
urlConnection.connect();
InputStream inputStream = urlConnection.getInputStream();
StringBuffer buffer = new StringBuffer();
if (inputStream == null) {
return null;
}
reader = new BufferedReader(new InputStreamReader(inputStream));
String line;
while ((line = reader.readLine()) != null)
buffer.append(line + "\n");
if (buffer.length() == 0)
return null;
return buffer.toString();
} catch (IOException e) {
Log.e(TAG, "IO Exception", e);
return null;
} finally {
if (urlConnection != null) {
urlConnection.disconnect();
}
if (reader != null) {
try {
reader.close();
} catch (final IOException e) {
Log.e(TAG, "Error closing stream", e);
}
}
}
}
#Override
protected void onPostExecute(String response) {
if(response != null) {
JSONObject json = null;
try {
json = new JSONObject(response);
} catch (JSONException e) {
e.printStackTrace();
}
JSONObject jsonResponse = null;
try {
jsonResponse = json.getJSONObject("Question1");
} catch (JSONException e) {
e.printStackTrace();
}
MainActivity.jsonPrint.setText((CharSequence) jsonResponse);
}
}
}
ERROR:
E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
Process: uk.co.jrtevents.fetchjsonfromurltest, PID: 4019
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:318)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
Caused by: java.lang.NullPointerException: Attempt to invoke a virtual method on a null object reference
at uk.co.jrtevents.fetchjsonfromurltest.fetchJSON.doInBackground(fetchJSON.java:31)
at uk.co.jrtevents.fetchjsonfromurltest.fetchJSON.doInBackground(fetchJSON.java:18)
at android.os.AsyncTask$2.call(AsyncTask.java:304)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
LINE 31:
urlConnection.setRequestMethod("GET");
HttpURLConnection urlConnection = null;
You never assign a value to urlConnection, and so it is null.
You would need to add:
urlConnection = url.openConnection();
before trying to use urlConnection.
URL and HttpURLConnection are very old, and very few developers use them anymore. You may have better luck using more modern HTTP client APIs, such as OkHttp.
I am trying to call a rest web api that is hosted in a server.But i am getting
java.net.ConnectException: Failed to connect to /10...***:45.
It is POST method,passing JSON as parameter.
CommonAsyncTask cat=new CommonAsyncTask(MainActivity.this,jsonParam,1);
cat.delegate = MainActivity.this;
cat.execute(getResources().getString(R.string.url));
I am able open connection but error occurs when i try to getOutputstream on HttpURLConnection object.
Is this the correct way to call a web api written in asp.net from android?
if yes ,please help me fix this error.
public class CommonAsyncTask extends AsyncTask<String, Integer, String> {
JSONObject params;
// private ProgressDialog progressDialog = null;
Context mContext;
public AsyncResponse delegate = null;
public static final int POST_TASK = 1;
public static final int GET_TASK = 2;
private int taskType;
private ProgressDialog progressDialog = null;
InputStream is;
public CommonAsyncTask(Context mContext, JSONObject params, int taskType) {
this.mContext = mContext;
this.params = params;
this.taskType = taskType;
}
#Override
protected void onPreExecute() {
super.onPreExecute();
/*progressDialog = ProgressDialog.show(mContext, "Please wait",
"Connecting");
progressDialog.setCancelable(true);*/
}
#Override
protected String doInBackground(String... urls) {
// TODO Auto-generated method stub
String result = "";
try {
/*
* Communication with Webservice
*/
switch (taskType) {
case POST_TASK:
Log.d("TAG:","POSTT");
URL url = new URL(urls[0]);
Log.d("b4 con","here");
HttpURLConnection conn = (HttpURLConnection) url
.openConnection();
Log.d("after con.open","here");
conn.setRequestMethod("POST");
Log.d("seting post","here");
conn.setDoOutput(true);
Log.d("DOOUTPUT-true","here");
conn.setDoInput(true);
Log.d("DOinputPUT-true","here");
conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
Log.d("contenttype-json","here");
DataOutputStream wr = new DataOutputStream(conn.getOutputStream ());
Log.d("data outputstream","here");
wr.writeBytes(params.toString());
wr.flush();
wr.close();
Log.d("b4","conn.connect");
conn.connect();
int responsePostCode = conn.getResponseCode();
if(responsePostCode>=400){
is = conn.getErrorStream();
}
else{
is=conn.getInputStream();
}
BufferedReader in = new BufferedReader(new InputStreamReader(
is));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
result = response.toString();
Log.d("LWCP", "Response: " + result);
break;
case GET_TASK:
/*
* String query = String.format("mobile=%s",
* URLEncoder.encode(cid, "utf-8"));
*/
URL obj = new URL(urls[0]);
// URL obj = new URL(url[0] + "?mobile=" + cid);
HttpURLConnection con = (HttpURLConnection) obj
.openConnection();
con.setRequestMethod("GET");
int responseCode = con.getResponseCode();
Log.d("Sending'GET'request to:", urls + "");
Log.d("Response Code : ", responseCode + "");
Log.d("url-",urls[0]);
if(responseCode>=400){
is = con.getErrorStream();
}
else{
is=con.getInputStream();
}
BufferedReader inReader = new BufferedReader(
new InputStreamReader(is));
String inLine;
StringBuffer responseBuffer = new StringBuffer();
while ((inLine = inReader.readLine()) != null) {
responseBuffer.append(inLine);
}
inReader.close();
con.connect();
result = responseBuffer.toString();
Log.d("LWCP", "Response: " + result);
break;
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
return result;
}
protected void onPostExecute(String result) {
//progressDialog.dismiss();
delegate.processFinish(result);
}
}
sharing my log
D/TAG:: POSTT
D/b4 con: here
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
D/after con.open: here
D/seting post: here
D/DOOUTPUT-true: here
D/DOinputPUT-true: here
D/contenttype-json: here
W/System.err: java.net.ConnectException: Failed to connect to /10.142.173.112:45
at com.android.okhttp.internal.io.RealConnection.connectSocket(RealConnection.java:143)
at com.android.okhttp.internal.io.RealConnection.connect(RealConnection.java:112)
at com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:184)
at com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:126)
at com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:95)
W/System.err: at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:281)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:224)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:461)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:127)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:258)
at com.example.restcall.CommonAsyncTask.doInBackground(CommonAsyncTask.java:78)
at com.example.restcall.CommonAsyncTask.doInBackground(CommonAsyncTask.java:19)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
I am making a network call as instructed in developer.android.com (by using HttpURLConnection). Now I am getting a out of memory exception and app is getting crashed.
The following is the stack trace:
E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
Process: com.example.app, PID: 19869
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:318)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
Caused by: java.lang.OutOfMemoryError: Failed to allocate a 4294967306 byte allocation with 4056144 free bytes and 370MB until OOM
at com.example.app.webservices.HttpConnectionClass.readIt(HttpConnectionClass.java:158)
at com.example.app.webservices.HttpConnectionClass.downloadUrl(HttpConnectionClass.java:123)
at com.example.app.webservices.HttpConnectionClass.access$100(HttpConnectionClass.java:28)
at com.example.app.webservices.HttpConnectionClass$DownloadWebpageTask.doInBackground(HttpConnectionClass.java:52)
at com.example.app.webservices.HttpConnectionClass$DownloadWebpageTask.doInBackground(HttpConnectionClass.java:46)
at android.os.AsyncTask$2.call(AsyncTask.java:304)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
I've already included this in my manifest :
android:largeHeap="true"
This is my Networkclass:
public class HttpConnectionClass {
public static Activity context;
List json;
static boolean dialogIsShowing = true;
public String url;
List<NameValuePair> params = new ArrayList<NameValuePair>();
public void getPostResponse_WithAsyn(Activity context, String url, List json, String message) {
this.params = json;
this.url= url;
this.json = json;
Log.v("TAG","PARAMS::"+json.toString());
//add all the default parameters here
new DownloadWebpageTask().execute(url);
}
private class DownloadWebpageTask extends AsyncTask<String, Void, String> {
#Override
protected String doInBackground(String... urls) {
// params comes from the execute() call: params[0] is the url.
try {
return downloadUrl(urls[0]);
} catch (IOException e) {
e.printStackTrace();
return "Unable to retrieve web page. URL may be invalid.";
}
}
// onPostExecute displays the results of the AsyncTask.
#Override
protected void onPostExecute(String result) {
GetHttpPostResponse.myJsonResponse = result;
/*int maxLogSize = 1000;
for(int i = 0; i <= result.length() / maxLogSize; i++) {
int start = i * maxLogSize;
int end = (i+1) * maxLogSize;
end = end > result.length() ? result.length() : end;
Log.v("TAG_result", result.substring(start, end));
}
*/
Log.v("Connection class","Response::"+result);
}
}
private String downloadUrl(String myurl) throws IOException {
InputStream is = null;
// Only display the first 500 characters of the retrieved
// web page content.
int len =Integer.MAX_VALUE;
try {
URL url = new URL(myurl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
Log.v("TAG","CONNECTING URL::"+myurl);
conn.setReadTimeout(10000 /* milliseconds */);
conn.setConnectTimeout(15000 /* milliseconds */);
conn.setRequestMethod("POST");
conn.setDoInput(true);
conn.setDoOutput(true);
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("key1", ""));
params.add(new BasicNameValuePair("key2", ""));
Log.v("TAG","PARAMETERS::"+params.toString());
OutputStream os = conn.getOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
writer.write(getQuery(params));
writer.flush();
writer.close();
os.close();
// Starts the query
conn.connect();
int response = conn.getResponseCode();
String res_data = conn.getResponseMessage();
Log.d("TAG", "The response is: " + res_data);
is = conn.getInputStream();
// Convert the InputStream into a string
String contentAsString = readIt(is, len);
return contentAsString;
// Makes sure that the InputStream is closed after the app is
// finished using it.
} finally {
if (is != null) {
is.close();
}
}
}
private String getQuery(List<NameValuePair> params) throws IOException,UnsupportedEncodingException {
StringBuilder result = new StringBuilder();
boolean first = true;
for (NameValuePair pair : params) {
if (first)
first = false;
else
result.append("&");
result.append(URLEncoder.encode(pair.getName(), "UTF-8"));
result.append("=");
result.append(URLEncoder.encode(pair.getValue(), "UTF-8"));
}
return result.toString();
}
public String readIt(InputStream stream, int len) throws IOException, UnsupportedEncodingException {
Reader reader = null;
reader = new InputStreamReader(stream, "UTF-8");
char[] buffer = new char[len];
reader.read(buffer);
return new String(buffer);
}
}
And,I've Identified that "len" is the problem and tried to hardcode it but doesn't seem to work in all scenarios.
{"ResponseCode":"-1000","ResponseDesc":"Invalid user type."}�
Please help me out.
Try this readIt method,
public String readIt(InputStream stream) throws IOException, UnsupportedEncodingException {
StringBuffer sb = new StringBuffer();
BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8"));
String line;
while ((line = br.readLine()) != null){
sb.append(line);
}
br.close();
return sb.toString();
}
You are trying to do
int len =Integer.MAX_VALUE;
char[] buffer = new char[len];
do you have that much memory?
You are allocating char array of length Integer.MAX_LENGTH, which will not fit in the available memory. I think you would be better of to have readIt() look something like this:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int l;
while ((l = stream.read(buffer)) != -1) {
baos.write(buffer, 0, l);
}
return baos.toString("UTF-8");
What this error points out?
10-31 21:05:27.567 2496-2522/com.example.talha.appforblog E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #2
Process: com.example.talha.appforblog, PID: 2496
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.NullPointerException: println needs a message
at android.util.Log.println_native(Native Method)
at android.util.Log.d(Log.java:139)
at com.example.talha.appforblog.MainListActivity$DownloadXmlTaskContent.loadXmlFromNetworkContent(MainListActivity.java:294)
at com.example.talha.appforblog.MainListActivity$DownloadXmlTaskContent.doInBackground(MainListActivity.java:228)
at com.example.talha.appforblog.MainListActivity$DownloadXmlTaskContent.doInBackground(MainListActivity.java:217)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587at java.lang.Thread.run(Thread.java:818)
This is my asynTask class. I have implemented 2 AsyncTask.. First asynctask does give any error but when i implemented this(second) AsyncTask , this is what i m getting message
private class DownloadXmlTaskContent extends AsyncTask<String, Void,List<ContentGetter.Content> > {
private Exception mException = null;
private Context mContext;
public DownloadXmlTaskContent(Context context) {
mContext = context;
}
#Override
protected List<ContentGetter.Content> doInBackground(String... urls) {
try {
return loadXmlFromNetworkContent(urls[0]);
} catch (IOException e) {
mException = e;
} catch (XmlPullParserException e) {
mException = e;
}
return null;
}
#Override
protected void onPostExecute(List<ContentGetter.Content> results) {
if (results != null && mException == null) {
} else {
if (mException instanceof IOException){
} else if (mException instanceof XmlPullParserException) {
}
}
}
private List<ContentGetter.Content> loadXmlFromNetworkContent(String urlString) throws XmlPullParserException, IOException {
InputStream stream = null;
// Instantiate the parser
ContentGetter contentgetter = new ContentGetter();
// for fetching the list view
List<ContentGetter.Content> content = null;
String summary = null;
try {
stream = downloadUrl(urlString);
content= contentgetter.parse(stream,urlBlogtitle);
Log.d(TAG,content.get(0).summary);
// Makes sure that the InputStream is closed after the app is
// finished using it.
} finally {
if (stream != null) {
stream.close();
}
}
return content;
}
// Given a string representation of a URL, sets up a connection and gets
// an input stream.
private InputStream downloadUrl(String urlString) throws IOException {
URL url = new URL(urlString);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(10000 );
conn.setConnectTimeout(15000 );
conn.setRequestMethod("GET");
conn.setDoInput(true);
// Starts the query
conn.connect();
return conn.getInputStream();
}
In the line Log.d(TAG,content.get(0).summary);, content.get(0).summary is probably null
You should do a check to see if it's null before trying to print it, and/or add a catch statement in your try block
Log.d(TAG,content.get(0).summary != null ? content.get(0).summary : "NULL");
try {
stream = downloadUrl(urlString);
content= contentgetter.parse(stream,urlBlogtitle);
Log.d(TAG,content.get(0).summary != null ? content.get(0).summary : "NULL");
// Makes sure that the InputStream is closed after the app is
// finished using it.
} catch (NullPointerException e) {
Log.d("ERROR","Response is null!");
} finally {
if (stream != null) {
stream.close();
}
}
Be sure no null is passed to Log.d() method. Check it in your code: Log.d(TAG,content.get(0).summary);
So first of all I'm trying to do a Client Socket and ASync Task program using android.
It builds and installs successfully, but when I open the application, it crashes and logcat says that
"E/AndroidRuntime( 271): FATAL EXCEPTION: AsyncTask #1
E/AndroidRuntime( 271): java.lang.RuntimeException: An error occured while executing doInBackground()"
public class AsyTask extends AsyncTask<String, Void, String> {
protected String doInBackground(String... ad) {
Socket socket = null;
OutputStream os = null;
StringBuffer output = null;
try {
socket = new Socket(ad[0], Integer.parseInt(ad[1]));
} catch (java.lang.Exception e) {
e.printStackTrace();
}
try {
os = socket.getOutputStream();
os.write("GET / \r\n".getBytes());
os.flush();
output = new StringBuffer("");
InputStream is = socket.getInputStream();
BufferedReader bufReader = new BufferedReader(new InputStreamReader(new BufferedInputStream(is)));
String line = "";
while ((line = bufReader.readLine()) != null) {
output.append(line);
output.append("\n");
}
bufReader.close();
} catch (Exception e) {
e.printStackTrace();
}
return output.toString();
}
protected void onPostExecute(String result) {
System.out.println(result);
}
}