简体   繁体   English

如何在Soap Web服务中添加“内容类型”标头

[英]How to add “content-type” header in soap webservice

I've seen several different examples and I can't get any to work. 我已经看到了几个不同的示例,但是我什么也做不了。 My goal is to add a content type of JSON to my request. 我的目标是向我的请求添加JSON的内容类型。 Without the header, my request doesn't error: 没有标题,我的请求不会出错:

  public void calculate() {
        String SOAP_ACTION = "http://----/--";
        String METHOD_NAME = "----";
        String NAMESPACE = "http://-----/";
        String URL = "http://----/---/----.asmx";
        try {
            // Creating a new empty SOAP message object

            SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
            Request.addProperty("username", "***");
            Request.addProperty("password", "****");
            SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            soapEnvelope.dotNet = true;
            soapEnvelope.setOutputSoapObject(Request);

            HttpTransportSE transport = new HttpTransportSE(URL);


            transport.call(SOAP_ACTION, soapEnvelope);

            resultString = (SoapPrimitive) soapEnvelope.getResponse();

            Log.i(TAG, "Result Celsius: " + resultString);
        } catch (Exception ex) {
            Log.e(TAG, "Error: " + ex.getMessage());
        }
    }

Try this, 尝试这个,

// Create a of HeaderProperty
List<HeaderProperty> headerList = new ArrayList<HeaderProperty>();
// Add Content-Type to the list
headerList.add(new HeaderProperty("Content-Type", "application/json; charset=UTF-8"));

// Pass this list as 3rd argument to call method
transport.call(SOAP_ACTION, soapEnvelope, headerList);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使Content-Type标头为可选? - How to make Content-Type header optional? 如何将HTTP标头添加到soap webservice glassfish - how to add http header to soap webservice glassfish 由于新服务器不支持SOAPMessage内容类型,Weblogic 9.2 Web服务客户端SOAP错误 - Weblogic 9.2 webservice client SOAP Fault due to SOAPMessage content-type not supported in new server 如何以编程方式(在TomEE中)获取SOAP请求的内容类型和编码? - How to obtain content-type and encoding of a SOAP request programmatically (in TomEE)? 如何使用SOAP UI测试响应内容类型 - How to test the response content-type using SOAP UI 无法将内容类型标头添加到SSE端点 - Unable to add Content-Type Header to SSE endpoint 如何添加内容类型 header application/json 以取消映射后端点? - How to add content-type header application/json to void postmapping endpoint? 尝试使用Apache Tomcat托管的Web服务时,WebServiceexception“标头中没有内容类型” - WebServiceexception “No Content-type in the header” when trying to consume Apache Tomcat hosted webservice 无法在SOAP请求上设置Content-Type - Unable to set Content-Type on SOAP Request 如何根据Content-type添加响应头; 在提交响应之前获取Content-type - How to add response headers based on Content-type; getting Content-type before the response is committed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM