请问,怎样使用httpclient向服务器传头文件和json 对象
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);
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);
更多追问追答
追问
谢谢你
另外有一个key就是要上传的json对象的key,是不是就是那个JSON,我这边的字段是value,可以直接替换了吧?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询