我试图通过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