猴子请来的救兵_
2015-01-27 15:47
采纳率: 94.7%
浏览 8.1k

android的HttpPost怎么传byte数组给服务器

我用httpurlconnection传就可以,用httppost就不行了。。。

httpurlconnection = (HttpURLConnection) url.openConnection();
httpurlconnection.setDoOutput(true);
httpurlconnection.setRequestMethod("POST");
httpurlconnection.getOutputStream().write(param.getBytes("UTF-8"));
httpurlconnection.getOutputStream().close();
这样就能调通接口

HttpClient client = new DefaultHttpClient();
HttpPost request = new HttpPost(url);
ByteArrayEntity arrayEntity = new ByteArrayEntity(encodeParameters(params, "utf-8"));
arrayEntity.setContentType("application/octet-stream");
request.setEntity(arrayEntity);
HttpResponse response = client.execute(request);

这样却不行,httppost要怎样传byte啊

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • save4me 2015-01-28 07:03
    已采纳

    你的encodeParameters是自己写的函数吗?使用request.setEntity(new UrlEncodedFormEntity(params));试一下

    点赞 打赏 评论

相关推荐 更多相似问题