Im編寫一個RESTful API & Android客戶端在我去的同時,我正在從服務器拉取用戶配置文件。我覺得這應該肯定是一個獲取請求,即時通訊只提取現有數據,即時通訊不向數據庫添加/編輯任何內容,但我需要一個user_id參數才能查詢相應的配置文件。我可以只發送一個微小的變量和我的HttpGet一起,在這種情況下我該如何還是應該使用HttpPost?我可以用1個字符串參數發送Android HttpGet(不是HttpPost)嗎?
0
A
回答
0
Android使用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
相關問題
- 1. Android使用HttpPost/HttpGet發送照片
- 2. 發送給PowerShell的字符串參數不是一個字符串嗎?
- 3. 在Android中使用HttpPost發佈JsonArray和字符串參數
- 4. .net webapi HttpGet vs HttpPost。爲什麼HttpGet?
- 5. 我們是否可以隱式傳遞HttpGet查詢字符串
- 6. Android HttpGet請求不發送
- 7. MVC HttpGet和HttpPost
- 8. 我可以向New Relic發送字符串嗎?
- 9. HTTPPost參數發送問題
- 10. 我可以使用ExpressJS遍歷查詢字符串參數嗎?
- 11. 差異btwn HttpPost&HttpGet在android
- 12. HTTPPOST請求與字符串參數
- 13. Android - 獲取httpPost字符串
- 14. 我可以使用字符串str =「id」,然後person.str = 1嗎?
- 15. 我可以用帶這個參數的字符串做一個switch語句嗎?
- 16. 我們可以發送一個模板參數嗎?另一對
- 17. 我們可以發送一個參數給C#中的TestInitialize嗎?
- 18. 我可以通過UIHint控制參數發送一個SelectList嗎?
- 19. 我可以向刪除方法發送一個參數嗎?
- 20. 我可以使用asm函數而不是以字符串文字作爲參數的c-string變量嗎?
- 21. 我們可以發送圖像作爲字符串參數在webserrvices在android123
- 22. HttpPost參數不接受10位數字作爲字符串
- 23. HttpPost和HttpGet不工作?
- 24. 我可以只發布json字符串(不帶「name =」)嗎?
- 25. Android不發送json字符串
- 26. 發送的請求體參數而不是查詢字符串
- 27. file_get_contents()期望參數1是字符串,
- 28. mysql_real_escape_string()預計參數1是字符串
- 29. 我可以區分字符串文字參數和計算爲字符串的參數嗎?
- 30. 的Android HttpPost不帶參數的名字