android 中的 application/soap+msbin1

发布于 2024-12-09 05:17:48 字数 886 浏览 1 评论 0原文

我只需要通过正常的 HTTP POST 向 Web 服务发送请求即可获得响应。我在主体上很好地传递了所需的参数。当我运行它时,我收到“无法处理消息,因为内容类型‘text/json’不是预期类型为“application/soap+msbin1”。”错误。当我对此进行研究时。由于“Web 服务要求请求具有特定的内容类型,即“application/soap+msbin1”。当我替换预期的内容类型时。我得到了错误请求错误。不知道如何从中恢复

: ……

    DefaultHttpClient httpClient = new DefaultHttpClient();
    ResponseHandler <String> resonseHandler = new BasicResponseHandler();
    HttpPost postMethod = new HttpPost("My URL");
    postMethod.setHeader( "Content-Type", "text/json"); 
    postMethod.setHeader( "Cache-Control", "no-cache"); 



    JSONObject json = new JSONObject();
    json.put("userName", "My Username");
    json.put("password", "My Password");
    json.put("isPersistent",false);


    postMethod.setEntity(new ByteArrayEntity(json.toString().getBytes("UTF8")));
    HttpResponse  response = httpClient.execute(postMethod);

I just need to send request to webservice via normal HTTP POST inorder to get response.I passed required parameter on body well.While i run it.,i got "Cannot process the message because the content type 'text/json' was not the expected type 'application/soap+msbin1'." error.When i made research over this.,due to "Web Service required the request to have a specific Content-Type, namely "application/soap+msbin1".When i replaced expected content type.,i got Bad Request error.I donno how to recover from that.

My code:
...

    DefaultHttpClient httpClient = new DefaultHttpClient();
    ResponseHandler <String> resonseHandler = new BasicResponseHandler();
    HttpPost postMethod = new HttpPost("My URL");
    postMethod.setHeader( "Content-Type", "text/json"); 
    postMethod.setHeader( "Cache-Control", "no-cache"); 



    JSONObject json = new JSONObject();
    json.put("userName", "My Username");
    json.put("password", "My Password");
    json.put("isPersistent",false);


    postMethod.setEntity(new ByteArrayEntity(json.toString().getBytes("UTF8")));
    HttpResponse  response = httpClient.execute(postMethod);

...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏末的微笑 2024-12-16 05:17:48

您似乎正在尝试调用 WCF SOAP 服务。该服务需要正确的 SOAP 通信(= 没有 JSON),而且它使用 SOAP 消息的 MS 二进制消息编码(即内容类型描述的内容)不可互操作,因此我怀疑您是否能够在 Android 设备上使用它(除非您发现Java / Android 编码的实现)。

It looks like you are trying to call WCF SOAP service. That service expects correct SOAP communication (= no JSON) and moreover it uses MS binary message encoding of SOAP messages (that is what content type describes) is not interoperable so I doubt you will be able to use it on Android device (unless you find implementation of that encoding for Java / Android).

如果没结果 2024-12-16 05:17:48
HttpPost request = new HttpPost(url);    
StringEntity entity = new StringEntity(json.toString());
                             entity.setContentType("application/json;charset=UTF-8");                            entity.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,"application/json;charset=UTF-8"));
                             request.setHeader("Accept", "application/json");
                             request.setEntity(entity); 

try{
DefaultHttpClient httpClient = new DefaultHttpClient();
    response = httpClient.execute(request); 
}

尝试使用这样的东西。它对我有用。

谢谢。
N_JOY。

HttpPost request = new HttpPost(url);    
StringEntity entity = new StringEntity(json.toString());
                             entity.setContentType("application/json;charset=UTF-8");                            entity.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,"application/json;charset=UTF-8"));
                             request.setHeader("Accept", "application/json");
                             request.setEntity(entity); 

try{
DefaultHttpClient httpClient = new DefaultHttpClient();
    response = httpClient.execute(request); 
}

Try using something like this. it worked for me.

Thanks.
N_JOY.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文