我正在尝试使用在网站的URL中传递的值发送HTTP GET请求
http://somenthing.com/c/chk.php?val=somevalue
我使用了以下代码,但它似乎无法正常工作
HttpResponse response = null;
try {
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet();
request.setURI(new URI("http://somenthing.com/c/chk.php?val=somevalue"));
response = client.execute(request);
}
catch (URISyntaxException e)
{
e.printStackTrace();
}
catch (ClientProtocolException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
return;
我没有收到任何错误,上面的代码在按下按钮时起作用,并且我已经使用了该权限。
收到HTTP GET请求后,后端进程由服务器完成。
答案 0 :(得分:0)
我的解决方案是:
// ---Connects using HTTP GET---
public static InputStream OpenHttpGETConnection(String url) {
InputStream inputStream = null;
try {
HttpClient httpclient = new DefaultHttpClient();
HttpResponse httpResponse = httpclient.execute(new HttpGet(url));
inputStream = httpResponse.getEntity().getContent();
} catch (Exception e) {
Log.d("InputStream", e.getLocalizedMessage());
}
return inputStream;
}