인스턴트 메시징 RESTful API & 안드로이드 클라이언트와 나는 현재 서버에서 사용자 프로파일을 가져 오기 위해 노력하고 있습니다. 나는 이것이 분명히 기존의 데이터를 가져오고 내 데이터베이스에 아무 것도 추가/편집하지 않는 요청을 받아야한다는 느낌이 들지만 적절한 프로필을 쿼리 할 수 있으려면 user_id 매개 변수가 필요합니다. HttpGet과 함께 하나의 작은 변수 만 보낼 수 있습니까? 또는 어떻게해야합니까? HttpPost를 사용하지 않아도됩니까?1 문자열 매개 변수로 Android HttpGet (HttpPost 아님)을 보낼 수 있습니까?
0
A
답변
0
안드로이드는 Apache's HTTPClient를 사용합니다. 따라서 복사 중입니다. tutorial code :
public void sendStringTo(String remoteUrl, String myString) {
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(remoteUrl+"?string1="+myString);
HttpResponse response1 = httpclient.execute(httpGet);
// The underlying HTTP connection is still held by the response object
// to allow the response content to be streamed directly from the network socket.
// In order to ensure correct deallocation of system resources
// the user MUST either fully consume the response content or abort request
// execution by calling HttpGet#releaseConnection().
try {
System.out.println(response1.getStatusLine());
HttpEntity entity1 = response1.getEntity();
// do something useful with the response body
// and ensure it is fully consumed
EntityUtils.consume(entity1);
} finally {
httpGet.releaseConnection();
}
return;
}
0
GET
은 변수/매개 변수 추가를 지원할 수 있습니다. 예를 들어, 당신은이처럼 보이는 Url
을 만들 수 :
http://yourwebsite.com/script.php?user_id=19898424