我可以知道这个http连接有什么问题吗? 运行时我得到“HTTP问题”。
public void makeHttpPost(){
try
{
//http post
HttpPost httppost = new HttpPost("http://10.0.2.2/project/login.php");
HttpClient httpclient = new DefaultHttpClient();
httppost.setEntity(new UrlEncodedFormEntity(namevaluepairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}
catch(Exception e)
{
Toast.makeText(getBaseContext(),e.toString() ,Toast.LENGTH_LONG).show();
Toast.makeText(getBaseContext(),"HTTP PROBLEM",Toast.LENGTH_LONG).show();
}
}
答案 0 :(得分:1)
调用以下类,其中你称为makeHttpPost() 如下所示调用此类:
new LoadData().execute();
class LoadData extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
// ur http code
makeHttpPost();
return null;
}
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
}
}