Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular2 posting XML type request data using HTTP

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>
like image 520
vishnu Avatar asked Oct 30 '22 20:10

vishnu


1 Answers

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);
like image 189
Pankaj Parkar Avatar answered Nov 11 '22 13:11

Pankaj Parkar