請再具體些。什麼不行?此代碼是你可以用什麼做的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