2016-12-13 2 views
0

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を使用している間にも、このエラーが両方とも私のローカル開発環境とオンラインのサーバー環境で起こった、起こりました。

私のコードに何か間違いがあるはずです。

ヒントはありますか?

ありがとうございます。

答えて

1

これは、CORS (Cross-Origin Resource Sharing)というヘッダーがそのドメインを要求できないためです。

オプション1問題のドメインを制御する場合、CORSヘッダーを追加してコールを許可できます。私はあなたがドメインをコントロールしていない場合は、.htaccessファイルに

Header set Access-Control-Allow-Origin "*" 

オプション2を設定することができ、あなたが使ってそのドメインにあなたはAJAX呼び出しを行うことができますし、リバースプロキシを使用する必要がありますので、そのサーバーがApacheを使用して見ることができますあなた自身のドメイン。

+0

ええ、データを取得するために中間層を構築する必要があることがわかりました。ありがとう。 – Joe

+0

あなたは大歓迎です:) –

関連する問題