public class HttpHandle extends AsyncTask<String, Void, Void> {
List<NameValuePair> parm;
HttpClient client;
HttpPost post;
String responseBody;
HttpResponse response;
XMLParser parser;
org.w3c.dom.Document doc;
public HttpHandle(String url,int full) {
client = new DefaultHttpClient();
post = new HttpPost(url);
parm = new ArrayList<NameValuePair>(full);
this.responseBody = "";
}
public void addInfo(String key, String value)
{
parm.add(new BasicNameValuePair(key, value));
}
public String getRes()
{
return this.responseBody;
}
@Override
protected Void doInBackground(String... params) {
// TODO Auto-generated method stub
try {
post.setEntity(new UrlEncodedFormEntity(parm,HTTP.UTF_8));
response = client.execute(post);
this.responseBody = EntityUtils.toString(response.getEntity());
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
protected void onPostExecute() {
// Call onRefreshComplete when the list has been refreshed.
super.onPostExecute(null);
}
}
我正在使用此類從我的應用發送帖子請求,但是當我嘗試在手機上運行它時,應用崩潰。當我嘗試發送帖子請求時,我的應用崩潰了android
這是我用我的登錄活動代碼:
String user = username.getText().toString();
String pass = password.getText().toString();
HttpHandle handle = new HttpHandle("url",2);
handle.addInfo("username", user);
handle.addInfo("password", pass);
String responseBody = handle.execute();
我發現了很多解決方案,但我沒有成功,使其工作。 日誌錯誤:
02-08 19:58:00.252: D/before(4048): From HERE 02-08 19:58:00.262: D/libc(4048): [NET] getaddrinfo hostname www.raffle.coder.co.il, servname NULL, ai_family 0 02-08 19:58:00.272: D/libc(4048): [NET] getaddrinfo hostname www.raffle.coder.co.il, servname NULL, ai_family 0 02-08 19:58:00.272: I/global(4048): call createSocket() return a new socket. 02-08 19:58:00.272: D/libc(4048): [NET] getaddrinfo hostname 80.179.219.93, servname NULL, ai_family 0
現在,當我試着點擊「登錄」按鈕沒有happneds。
發佈您的'logcat',它包含有關導致您的應用程序崩潰的錯誤的詳細信息 –