我正在尝试在角度4中使用带有ngx-soap包的SOAP服务器。
但是,我收到了跨源请求错误(服务器端无法访问,但没有问题,Access-Control-Allow-Origin很好),http状态代码为400.
我真的不知道为什么会出现这个错误。请帮帮我。
所以这是我的代码(来自ngx-soap包)。
他创建了SOAP客户端,调用SOAP服务器(http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso)并使用发布请求从CountryName操作中恢复国家/地区名称。
export class AppComponent implements OnInit{
jsonResponse: any;
xmlResponse: string;
message: string;
loading: boolean;
sCountryISOCode: string;
private client: Client;
constructor(
private http: HttpClient,
private soap: SOAPService
) { }
ngOnInit() {
this.http.get('/assets/tt.wsdl',
{responseType: 'text'}).subscribe(response => {
console.log(response);
if (response) {
this.client = this.soap.createClient(response);
}
});
}
soapCall() {
this.clear();
this.loading = true;
const body = {
sCountryISOCode: this.sCountryISOCode
};
this.client.operation('CountryName', body)
.then(operation => {
console.log(operation);
if (operation.error) {
console.log('Operation error', operation.error);
return;
}
console.log(operation.url);
console.log(operation.xml);
console.log(operation.headers);
this.http.post(operation.url, operation.xml,
{ headers: operation.headers, responseType: 'text', withCredentials: true }).subscribe(
response => {
console.log('GG');
this.xmlResponse = response;
this.jsonResponse = this.client.parseResponseBody(response);
try {
this.message = this.jsonResponse.Body.AddResponse.AddResult;
} catch (error) { }
this.loading = false;
},
err => {
console.log('Error calling ws', err);
this.loading = false;
console.log();
}
);
})
.catch(err => console.log('Error', err));
}
clear() {
this.message = undefined;
this.jsonResponse = undefined;
this.xmlResponse = undefined;
}
}
export interface Output {
AddResult?: string;
}