问题描述
- 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啊
解决方案
你的encodeParameters是自己写的函数吗?使用request.setEntity(new UrlEncodedFormEntity(params));试一下
时间: 2025-01-21 05:13:16