angular2使用HTTP发布XML类型请求数据

时间:2016-09-14 07:09:40

标签: ajax angular ionic2 angular2-http

我可以通过以下方式将JSON请求数据发布到服务器,但是如何使用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>

1 个答案:

答案 0 :(得分:2)

您应在Content-Type对象

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