Httpclient Error
I'm tring to use http client to perform some simple snmp operations via a php script on a web server. So the php script listen to GET parameters. Here is my code: EditText host
Solution 1:
you can not make it in the UI thread
Here is an example using AsyncTask
EditTexthost= (EditText)findViewById(R.id.editText);
EditTextport= (EditText)findViewById(R.id.editText2);
EditTextcommunity= (EditText)findViewById(R.id.editText3);
Stringurl="http://192.168.0.102/za/getstatus.php?host=" + host.getText().toString() + "&port=" + port.getText().toString() + "&com=" + community.getText().toString() + "&oid=" + 2 + "&port1=" + 2;
newTask(url).execute();
}
classTaskextendsAsyncTask<Void, Void, HttpResponse>{
private String url;
Task(String url) {
this.url = url;
}
@Overrideprotected HttpResponse doInBackground(Void... voids) {
HttpClienthttpclient=newDefaultHttpClient();
// Prepare a request objectHttpPosthttpPost=newHttpPost(url);
try {
return httpclient.execute(httpPost);
} catch (ClientProtocolException e) {
// writing exception to log
e.printStackTrace();
} catch (IOException e) {
// writing exception to log
e.printStackTrace();
returnnull;
}
@OverrideprotectedvoidonPostExecute(HttpResponse httpResponse) {
super.onPostExecute(httpResponse);
if(httpResponse != null){
Log.d("Http Response:", response.toString());
}
}
}
Post a Comment for "Httpclient Error"