gpt4 book ai didi

java - 如何在soap webservice中添加 "content-type" header

转载 作者:行者123 更新时间:2023-12-01 09:30:36 25 4
gpt4 key购买 nike

我看过几个不同的例子,但我无法让任何一个工作。我的目标是向我的请求添加 JSON 内容类型。没有 header ,我的请求不会出错:

  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());
}
}

最佳答案

试试这个,

// 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);

关于java - 如何在soap webservice中添加 "content-type" header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39444866/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com