我試圖通過Java來POST請求發送到我的PHP頁面在Android Studio中httppost導致應用程序崩潰
首先我想httppost和按鍵
然後我讀了之後,應用程序崩潰我必須使用新的線程,我這樣做,但仍
應用程序崩潰
這裏是代碼:
public void send() {
final String name,phone,fb;
EditText one,two,three;
one=(EditText) findViewById(R.id.editText);
two=(EditText) findViewById(R.id.editText2);
three=(EditText) findViewById(R.id.editText3);
name=one.getText().toString();
phone=two.getText().toString();
fb=three.getText().toString();
Thread T=new Thread(new Runnable() {
@Override
public void run() {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://test.com/test.php");
try {
List <NameValuePair> nameValuePairs= new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("name",name));
nameValuePairs.add(new BasicNameValuePair("number",phone));
nameValuePairs.add(new BasicNameValuePair("fbname",fb));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response= httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
});
T.start();
}
日誌:http://pastebin.com/KQ9Y3rrG
安置自己的日誌跟蹤 – Rami
@Rami HTTP ://pastebin.com/MtgG62G2 – user2973413
將'e.printStackTrace();'添加到'catch'塊並更新你的logtrace。 – Rami