我看到這個tutorial。如何發送與JSON身體和網址參數http後?
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("username", "John"));
params.add(new BasicNameValuePair("password", "pass"));
httpPost.setEntity(new UrlEncodedFormEntity(params));
和
String json = "{"id":1,"name":"John"}";
StringEntity entity = new StringEntity(json);
httpPost.setEntity(entity);
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-type", "application/json");
我想發送POST HTTP請求,在身體和網址參數
JSON如果我按照本教程中的例子,
會把第二setEntity
覆蓋第一個setEntity
?
如果是的話,我該怎麼寫呢?
這是什麼目的?你已經在第一個代碼中發送了「UrlEncodedFormEntity」,你不能發送任何json。所以是的,第二個''setEntity''覆蓋了第一個。 – f1sh