在我的应用程序中,我将数据发送到我的 servlet 并获得响应。但是在某些 wifi 中它可以工作,而在某些 wifi 中它不起作用(gice 连接错误).. 不知道为什么.. 这是 MyAsyncTask.. 请帮助我...
private class MyAsyncTask extends AsyncTask<String, Integer, String>{
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
String s=postData(params);
return s;
}
protected void onPostExecute(String result){
pb.setVisibility(View.GONE);
Toast.makeText(getApplicationContext(), result, Toast.LENGTH_LONG).show();
}
protected void onProgressUpdate(Integer... progress){
pb.setProgress(progress[0]);
}
public String postData(String valueIWantToSend[]) {
// Create a new HttpClient and Post Header
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://192.168.1.105:8080/ServletParams/AndroidServlet");
String origresponseText="";
try {
// Add your data cnic,mobileNo,name,address,nextkin
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("param1",valueIWantToSend[0]));
nameValuePairs.add(new BasicNameValuePair("param1", valueIWantToSend[1]));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
/* execute */
HttpResponse response = httpclient.execute(httppost);
HttpEntity rp = response.getEntity();
origresponseText=readContent(response);
}
catch (ClientProtocolException e) {
// TODO Auto-generated catch block
}
catch (IOException e) {
// TODO Auto-generated catch block
}
String responseText = origresponseText.substring(7, origresponseText.length());
return responseText;
}