Android 将文件作为 ByteArray 上传到 WCF REST 服务
我需要使用 WCF Rest 服务发送字节数组文件。我必须使用 android 中的 HttpPost 方法发送数据。我正在使用的代码给出的状态为 HTTP/1.1 400 Bad Request 错误。
private final static String URI = "http://192.168.1.15/QueryService/Import/Test";
final HttpPost request = new HttpPost(URI);
final HttpClient httpClient = new DefaultHttpClient();
final ByteArrayEntity entity = new ByteArrayEntity(fileToBytes(pathToOurFile));
entity.setContentType("application/octet-stream");
entity.setChunked(true);
request.setEntity(entity);
final HttpResponse hr = httpClient.execute(request);
final StatusLine status = hr.getStatusLine();
httpClient.getConnectionManager().shutdown();
I need to send a byte arrray file using WCF rest services. I have to send the data using HttpPost method in android. The code which i am using give the status as HTTP/1.1 400 Bad Request error.
private final static String URI = "http://192.168.1.15/QueryService/Import/Test";
final HttpPost request = new HttpPost(URI);
final HttpClient httpClient = new DefaultHttpClient();
final ByteArrayEntity entity = new ByteArrayEntity(fileToBytes(pathToOurFile));
entity.setContentType("application/octet-stream");
entity.setChunked(true);
request.setEntity(entity);
final HttpResponse hr = httpClient.execute(request);
final StatusLine status = hr.getStatusLine();
httpClient.getConnectionManager().shutdown();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
很难判断您的请求有什么问题。解决此类错误的标准方法是:
It is difficult to tell what is wrong with your request. The standard way of resolving this kind of errors is:
我在 WCF 服务中也遇到了同样的问题。 400 Bad request 表示您传递给方法的请求参数值与方法的参数不匹配。我使用 Base64 字符串编码将文件作为方法参数传递。愿它能帮助你。
I was also facing same problem with WCF service. 400 Bad request means request parameter value which you are passing to method doesn't match with method's parameter. I have used Base64 string encoding to pass file as method parameter. May it'll help you.