2016-09-14 84 views
5

我能夠通過以下方式將JSON請求數據發佈到服務器,但是如何將XML結構化數據發佈到使用http的服務器。angular2發佈使用HTTP的XML類型請求數據

getAuthSeed(value) { 
     let params = "{'validateUsr': 'false'}"; 
     let headers = new Headers(); 
     headers.append('Content-Type', 'application/json'); 
     headers.append('params', params); 

     let url = 'tab-api/login/'+value.username+'/seed/false'; 

     let options = new RequestOptions({ 
      method: RequestMethod.Get, 
      url: url, 
      headers: headers 
     }); 

     return this.http.request(new Request(options)).map(
      result => { 
       let data = result.json(); 
       return data; 
      } 
     ) 
    } 

示例XML請求:

<pi:ReqPay xmlns:pi="http:schema/"> 
    <Head ver="1.0" ts="" orgId="" msgId=""/> 
    <Meta> 
    <Tag name="PAYRE" value=""/> 
    </Meta> 
    <Txn id="" note="" custRef="" refId="" refUrl="" ts="" type="PAY|COLLECT"> 
    <RiskScores> 
    <Score provider="ci" type="TXNRISK" value=""/> 
    </RiskScores> 
    <Rules> 
    <Rule name="MINAMOUNT" value=""/> 
    </Rules> 
</Txn> 
</pi:ReqPay> 

回答

2

您應該提到Content-Typetext/xmlHeaders對象

let params = "{'validateUsr': 'false'}"; 
let headers = new Headers(); 
headers.append('Content-Type', 'text/xml'); 
headers.append('params', params);