1
晚上好。Android httpclient multipart post
我有一個post請求這樣
-----------------------------17911109517875 Content-Disposition: form-data;
name="PERSON*1[F*2][2664]" value1
-----------------------------17911109517875 Content-Disposition: form-data;
name="PERSON*1[I*3][2776]" value2
-----------------------------17911109517875 Content-Disposition: form-data;
name="PERSON*1[O*4][2778]" value3
,並試圖通過HttpClient的從Android設備發送。
public String doMultipartPost(String url, List<NameValuePair> urlParameters) {
HttpContext localContext = new BasicHttpContext();
localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
HttpPost request = new HttpPost(url);
HttpProtocolParams.setUserAgent(client.getParams(), "My funcy UA");
MultipartEntity entity = new
MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
for (NameValuePair nvp : urlParameters) {
try {
entity.addPart(nvp.getName(), new StringBody(nvp.getValue()));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
request.setEntity(entity);
try {
HttpResponse response = client.execute(request, localContext);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return "post";
}
但如何-----------------------------17911109517875 Content-Disposition: form-data;
它是由MultipartEntity自動設置或我應該把它在某處的代碼寫?此代碼不起作用。
謝謝。
有同樣的問題,你有沒有找到解決方案? – Jim