【发布时间】: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