-1
中的服務器我有一個這種格式的網址"http://testserver.com/Test/[email protected]"
。我想發送到服務器和inturn我會得到一個Json格式"[{"status":"0"}]"
的響應。如何在android中實現這一點。如何將參數傳遞給android
中的服務器我有一個這種格式的網址"http://testserver.com/Test/[email protected]"
。我想發送到服務器和inturn我會得到一個Json格式"[{"status":"0"}]"
的響應。如何在android中實現這一點。如何將參數傳遞給android
您可以使用HttpClient
和其他Http*
類。
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet("http://testserver.com/Test/[email protected]");
HttpResponse response = client.execute(request);
// Check if server response is valid
StatusLine status = response.getStatusLine();
if (status.getStatusCode() != 200) {
throw new IOException("Invalid response from server [" + status.toString() + "]");
}
// Pull content stream from response
HttpEntity entity = response.getEntity();
InputStream inputStream = entity.getContent();
StringBuilder builder = new StringBuilder();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
}
//return result from buffered stream
String dataAsString = builder.toString();
JSONObject jsonObject = new JSONObject(dataAsString);
嗨,我搜索,但我爲NT得到確切的辦法..我很新Web部件。儘管它可能看起來很愚蠢,但對我來說卻不是。請給我答案,這將是非常有益的.. – Naruto 2013-02-10 05:09:23