我试图在 java 上使用 HttpRequest 方法,但它不起作用,这是我的代码
package com.example.phpconnect;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import android.util.Log;
public class httpHandler {
public String post(String posturl){
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(posturl);
Log.w("Se envio","Fase 1");
HttpResponse resp = httpclient.execute(httppost);
HttpEntity ent = resp.getEntity();
Log.w("Se envio","Fase 2");
String text = EntityUtils.toString(ent);
Log.w("Se envio","Fase 3");
return text;
}
catch(Exception e){
Log.w("Se envio","Error");
return "Error";
}
}
}
它工作正常,直到第一个日志,然后它抛出错误,请有人知道问题出在哪里?谢谢!