这是我的客户端代码,我在json对象中创建了json对象我已经把byte []和两个字符串我刚刚将位图转换为byte []而我已经在servlet上使用httppost我接收了它试图发送json data.how我可以收到byte []和两个字符串然后我必须在浏览器和两个字符串上显示它。
public void getServerData(byte[] img, String name, String gender)throws JSONException, ClientProtocolException, IOException {
ArrayList<String> stringData = new ArrayList<String>();
DefaultHttpClient httpClient = new DefaultHttpClient();
ResponseHandler<String> resonseHandler = new BasicResponseHandler();
HttpPost postMethod = new HttpPost(SERVER_URL);
postMethod.setHeader("Content-Type", "application/json");
JSONObject json = new JSONObject("mydata");
json.put("image", img);
json.put("name", name);
json.put("gender", gender);
postMethod.setEntity(new ByteArrayEntity(json.toString().getBytes(
"UTF8")));
String response = httpClient.execute(postMethod, resonseHandler);
Log.e("response :", response);
}
int doGet(request,response){}
我必须收到它。
答案 0 :(得分:1)
JSONObject.put
没有接受字节数组的重载,尝试将这些字节编码为base64字符串?
请参阅https://stackoverflow.com/questions/9845767/base64-encoder-java