请问,怎样使用httpclient向服务器传头文件和json 对象

2025-05-15 20:32:24
推荐回答(1个)
回答1:

//向服务器写json
JSONObject json = new JSONObject();
Object email = null;
json.put("email", email);
Object pwd = null;
json.put("password", pwd);
StringEntity se = new StringEntity( "JSON: " + json.toString());
se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
post.setEntity(se);

post.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
HttpResponse httpResponse = httpClient.execute(post);