【问题标题】:application/soap+msbin1 in androidandroid中的应用程序/soap+msbin1
【发布时间】:2011-10-11 09:56:28
【问题描述】:

我只需要通过普通的 HTTP POST 向 web 服务发送请求以获得响应。我在 body 上传递了所需的参数。当我运行它时,我得到“无法处理消息,因为内容类型 'text/json'不是预期的类型 'application/soap+msbin1'。”错误。当我对此进行研究时。由于“Web 服务要求请求具有特定的内容类型,即“应用程序/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);

...

【问题讨论】:

    标签: android json web-services soap


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:
      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。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-12-20
        • 1970-01-01
        • 2015-08-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多