我现在真的很痛苦,请帮我解决这个问题。我以前也尝试过向我的本地主机发出 http 请求,一切正常,但现在它不起作用,我不知道为什么。
我正在尝试从以下代码发出请求。
HttpClient httpclient = new DefaultHttpClient();
String result="";
try
{
HttpPost httppost = new HttpPost("http://[ip]/php/untitled.php");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
nameValuePairs.add(new BasicNameValuePair("email",this.userEmail));
nameValuePairs.add(new BasicNameValuePair("pwd",this.userpassword));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity=response.getEntity();
if(entity!=null)
{
InputStream inputStream=entity.getContent();
result= convertStreamToString(inputStream);
}
}
catch (ClientProtocolException e)
{
Log.e("errorhai",e.getMessage());
}
catch (IOException e)
{
Log.e("errorhai",e.getMessage());
}
return result;
我还添加了互联网权限,但它仍然一直说
Connect to [ip] timed out.
当我在浏览器中输入网址时,它工作正常,但在这里不起作用。请告诉我这个问题的原因是什么?