请再具体些。什么不行?此代码是你可以用什么做的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
}
我wampserver使用所以我必须以“http://10.0.2.2/folder/script.php?value1=something&value2=更换网址东西“这个网址是否正确? – 2012-04-04 20:59:02
@Jamel:是的,如果你使用的是模拟器localhost是10.0.2.2。不要忘记将INTERNET权限添加到“AndroidManifest.xml”中。 – 2012-04-04 21:07:22
好吧,我会尝试这段代码,并希望这将工作:) – 2012-04-04 21:16:13