gpt4 book ai didi

javascript - 将 javascript fetch API 与 SOAP Web 服务一起使用

转载 作者:行者123 更新时间:2023-11-29 20:56:51 29 4
gpt4 key购买 nike

我在使用获取 API 发布到 SOAP Web 服务时遇到了非常困难的时间。我使用 chrome 插件解决了我的 CORS 问题,但现在我发送的格式似乎有问题。我已经尝试实现我在其他问题中看到的修复,尤其是在 Content-Type 和诸如此类的问题中,但我无法得到任何不同的结果。它只是不喜欢插槽 1 中的 <。

根据其他问题,我发送的实际“数据”看起来确实与其他 SOAP 请求有点不同......他们提到了一个信封,他们定义了一个 XML 版本,等等。我的是我发送的纯 XML 数据在本地的 SOAP 服务测试器中。所以我想我不知道的是,该软件是否在将请求“有效负载”发送到服务之前向其添加了额外的详细信息。

WSDL 不是很有用,但我可能找错了地方。

非常感谢任何建议。

我的 Javascript/获取:

var base64 = require('base-64');

let url = 'http://SCRB4APUSLSA801:9080/apex/services/argobasicservice';
let username = 'abo055';
let password = 'hidden';
let headers = new Headers();

export const N4RecordScan = {

submit(data) {

headers.append('Content-Type', 'text/xml');
headers.append('SOAPAction', 'basicInvoke');
headers.append('Authorization', 'Basic ' + base64.encode(username + ":" + password));

let dataPrefix = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:arg="http://www.navis.com/services/argobasicservice"><soapenv:Header/><soapenv:Body><arg:basicInvoke><arg:scopeCoordinateIds>APMT/USLAX/LAX/LAX</arg:scopeCoordinateIds><arg:xmlDoc><![CDATA[';
let dataSuffix = ']]></arg:xmlDoc></arg:basicInvoke></soapenv:Body></soapenv:Envelope>';

data = dataPrefix + data + dataSuffix;

console.log('about to send ' + data);

fetch(url, {
body: data,
method: 'POST',
mode: 'cors',
headers: headers,
credentials: 'include'
})
.then(response => console.log(response))
.catch(function(error) {
console.log(error);
});
//.done();

}
};

这是我要发送的数据:

<gate><record-scan><gate-id>USLAX</gate-id><stage-id>asd</stage-id><lane-id>asd</lane-id><external-console-id>asd</external-console-id><truck tag-id="asd" license-nbr="asd"/><equipment><container eqid="asd" on-chassis-id="asd" /><chassis eqid="asd"></chassis></equipment></record-scan></gate>

这是我得到的响应:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<soapenv:Fault>
<faultcode>soapenv:Server.userException</faultcode>
<faultstring>org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.</faultstring>
<detail>…</detail>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>

这是我要接触的服务的 WSDL。

<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.navis.com/services/argobasicservice" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="ArgobasicService" targetNamespace="http://www.navis.com/services/argobasicservice">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Argo Services</wsdl:documentation>
<wsdl:types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://www.navis.com/services/argobasicservice">
<xsd:element name="basicInvoke">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="scopeCoordinateIds" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="1" name="xmlDoc" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="basicInvokeResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="basicInvokeResponse" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="invokeRequest">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="scopeCoordinateIds" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="1" name="request" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="1" name="handler" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="1" name="locale" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="invokeResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="basicInvokeResponse" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
<wsdl:message name="basicInvokeRequest">
<wsdl:part element="tns:basicInvoke" name="basicInvoke"/>
</wsdl:message>
<wsdl:message name="basicInvokeResponse">
<wsdl:part element="tns:basicInvokeResponse" name="basicInvokeResponse"/>
</wsdl:message>
<wsdl:message name="invokeRequest">
<wsdl:part element="tns:invokeRequest" name="invokeRequest"/>
</wsdl:message>
<wsdl:message name="invokeResponse">
<wsdl:part element="tns:invokeResponse" name="invokeResponse"/>
</wsdl:message>
<wsdl:portType name="ArgobasicServicePort">
<!-- name of your wrapped method -->
<wsdl:operation name="basicInvoke">
<wsdl:input message="tns:basicInvokeRequest"/>
<wsdl:output message="tns:basicInvokeResponse"/>
</wsdl:operation>
<wsdl:operation name="invoke">
<wsdl:input message="tns:invokeRequest"/>
<wsdl:output message="tns:invokeResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ArgobasicServiceSoapBinding" type="tns:ArgobasicServicePort">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<!-- name of your wrapped method -->
<wsdl:operation name="basicInvoke">
<soap:operation soapAction=""/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="invoke">
<soap:operation soapAction=""/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="ArgobasicService">
<wsdl:port binding="tns:ArgobasicServiceSoapBinding" name="ArgobasicServicePort">
<soap:address location="http://scrb4apuslsa701:10080/apex/services/argobasicservice"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
( function(){ window.SIG_EXT = {}; } )()

最佳答案

您为每个请求重复使用相同的 Headers 对象。这意味着您每次发出新请求时都会添加新的授权 header 。

let headers = new Headers(); 移动到函数体中(并使用 const),可能使其工作!

关于javascript - 将 javascript fetch API 与 SOAP Web 服务一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48895327/

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