angular2 posting XML type request data using HTTP

此生再无相见时 提交于 2019-12-07 04:44:12

问题


I am able to post the JSON request data to server in the following way, but how do i post XML structured data to server using http.

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;
            }
        )
    }

sample XML request:

<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:


You should mention Content-Type as text/xml in your Headers object

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


来源:https://stackoverflow.com/questions/39484441/angular2-posting-xml-type-request-data-using-http

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!