SOAPのXML Ajax呼び出しポストマン(SOAPのXMLアヤックス)内のすべての良い:CSRFエラーがangular2で発生したが、ポストマンで
要求:
Method: Post
Url: https://domain.com/path
Content-Type: text/xml
Body:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cus="http://domain.com/">
<soapenv:Header/>
<soapenv:Body>
body message
</soapenv:Body>
</soapenv:Envelope>
応答:
<?xml version='1.0' encoding='UTF-8'?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<S:Body>
data returned
</S:Body>
そして、Angular2のコードは次のとおりです。
展開後//ServiceData as provider
import ****; //abbreviation
export class ServiceData {
private url = Setting.API_BASE_DATA;
private headers = new Headers({'Content-Type': 'text/xml;charset=utf-8',
'Accept': 'text/xml'});
constructor(
private http: Http,
) { }
getStatus(customerNumber: number): Observable<any> {
let data = `<soapenv:Envelope ...>......abbreviation......
</soapenv:Envelope>`; // the data are the same as the previous one.
return this.http.post(`${this.url}`, data, {headers: this.headers})
.map(response => {return response;})
.catch(err => {return Observable.throw(err);});
}
}
// Component
constructor(
private serviceData: ServiceData,
) {}
ngOnInit(): void{
this.serviceData.getStatus(384914)
.subscribe(response => console.log(response),
err => console.log(err));
}
は、エラーが発生しました:
XMLHttpRequest cannot load https://billingws.utilibill.com.au/tiabwsv2/UtbCustomer?wsdl. Origin domain is not allowed by Access-Control-Allow-Origin.
をネイティブのJavaScriptのAjaxを使用している間にも、このエラーが両方とも私のローカル開発環境とオンラインのサーバー環境で起こった、起こりました。
私のコードに何か間違いがあるはずです。
ヒントはありますか?
ありがとうございます。
ええ、データを取得するために中間層を構築する必要があることがわかりました。ありがとう。 – Joe
あなたは大歓迎です:) –