我正在研究应用程序,我想将坐标存储到本地数据库(wampserver)所以我已经完成了php脚本并且它可以工作,但我的问题是使用HTTP GET方法从我的应用程序执行该script.php.
我找到了这个代码,但它不起作用!! 所以,我需要你的帮助,谢谢!
链接到HTTP获取代码 - >:http://www.softwarepassion.com/android-series-get-post-and-multipart-post-requests/
请更具体一点.什么不起作用?此代码是您可以用来发出HTTP GET请求的代码:
HttpClient httpClient = new DefaultHttpClient();
String url = "http://www.mywebsite.com/script.php";
HttpGet httpGet = new HttpGet(url);
try {
HttpResponse response = httpClient.execute(httpGet);
StatusLine statusLine = response.getStatusLine();
if (statusLine.getStatusCode() == HttpStatus.SC_OK) {
HttpEntity entity = response.getEntity();
ByteArrayOutputStream out = new ByteArrayOutputStream();
entity.writeTo(out);
out.close();
String responseStr = out.toString();
// do something with response
} else {
// handle bad response
}
} catch (ClientProtocolException e) {
// handle exception
} catch (IOException e) {
// handle exception
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8573 次 |
| 最近记录: |