0
AsyncHttpClient版本是1.4.7。 服務器臨危請求,但無法找到該文件PARAMAndroid AsyncHttpClient:如何POST多部分表單數據?
AsyncHttpClient版本是1.4.7。 服務器臨危請求,但無法找到該文件PARAMAndroid AsyncHttpClient:如何POST多部分表單數據?
試試這個:
AsyncHttpClient client = new AsyncHttpClient();
RequestParams params = new RequestParams();
params.put("notes", "Test api support");
client.post(restApiUrl, params, responseHandler);
希望這有助於!
工作實例
HttpClient httpclient;
HttpPost httppost;
httpclient = new DefaultHttpClient();
httppost = new HttpPost(URLRepo.URL_IMAGESAVE);
List<BasicNameValuePair> nameValuePairs = new ArrayList<BasicNameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("user_id", ""+deichapp.getInt("userid", 0)));
//.. add parameters
File file = new File(new URI(obj.getString("fileUri")));
nameValuePairs.add(new BasicNameValuePair("filename", file.getName()));
httpclient.getParams().setParameter("Connection", "Keep-Alive");
httpclient.getParams().setParameter("Content-Type", "multipart/form-data;");
MultipartEntityBuilder entity = MultipartEntityBuilder.create();
for (BasicNameValuePair nameValuePair : nameValuePairs) {
entity.addTextBody(nameValuePair.getName(), nameValuePair.getValue());
}
entity.addPart("file", new FileBody(new File(new URI(obj.getString("fileUri")))));
httppost.setEntity(entity.build());
// Send and store the Image
HttpResponse response = httpclient.execute(httppost);
String json;
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
json = reader.readLine();
這裏使用了原生的Android API和沒有外部圖書館的像異步HTTP客戶端。確保您在後臺線程上執行此代碼。