0

I should send HTTP post request to another server from my angular app :

$http({
method: 'POST',
url:'www.example.com/SearchHotel.php',
data:
'<?xml version="1.0" encoding="utf-8"?>
 <Service_SearchHotel>
   <AgentLogin>
    <AgentId>xxx</AgentId>
    <LoginName>xxxx</LoginName>
    <Password>xxx</Password>
   </AgentLogin>
 <SearchHotel_Request>
  <PaxPassport>MA05110184</PaxPassport>
   <DestCountry>WSASTH</DestCountry>
    <DestCity>WSASTHBKK</DestCity>
     <HotelId InternalCode=""></HotelId>
      <Period checkIn="2017-10-26" checkOut="2017-10-28" />
       <RoomInfo>
        <AdultNum RoomType="Twin">2</AdultNum>
         <ChildAges />
       </RoomInfo>
        <flagAvail>Y</flagAvail>
   </SearchHotel_Request>
 </Service_SearchHotel>'
,
headers: { 
'Content-Type' :'multipart/form-data',
'Content-Disposition': 'form-data', 
**'name':"requestXML",**
'Accept':'application/xml',
'Access-Control-Allow-Origin':'*',
'Access-Control-Allow-Methods':'GET,PUT,POST,DELETE',
'Access-Control-Allow-Headers':'Content-Type'
}
}).then(function(error,response){
if (error) {
console.log(error);
}else{
 console.log(response)
}

which requestXML is mandatory from servar on google postman data return as normal but in my app always return :

"<?xml version="1.0" encoding="utf-8"?>↵<Service_SearchHotel>↵  <SearchHotel_Response>↵    <Error>↵      <ErrorDescription>Invalid Tag XML</ErrorDescription>↵    </Error>↵  </SearchHotel_Response>↵</Service_SearchHotel>↵"

and give me Invalid Tag XML . how I should pass requestXML to my post data because Im sure its from this becuse before I add this part to postman its return me same error . If any help will save me so much time

PS: 'Content-Disposition': 'form-data', **'name':"requestXML",** this part I copy from postman, before I try 'Content-Type' :'application/xml', and data like : data:'XML Request :<?xml version="1.0" encoding="utf-8"?>........ and get same error

1 Answer 1

0

Maybe take a look here: https://groups.google.com/forum/#!topic/rest-assured/QPjllwl8ins

Essentially, you need to specify a content boundary and place that boundary at the beginning and end of data

$http({
method: 'POST',
url:'www.example.com/SearchHotel.php',
data:
'------MuhUniqueIdX8nBO7q27yQ1JNb
<?xml version="1.0" encoding="utf-8"?>
 <Service_SearchHotel>
   <AgentLogin>
    <AgentId>xxx</AgentId>
    <LoginName>xxxx</LoginName>
    <Password>xxx</Password>
   </AgentLogin>
 <SearchHotel_Request>
  <PaxPassport>MA05110184</PaxPassport>
   <DestCountry>WSASTH</DestCountry>
    <DestCity>WSASTHBKK</DestCity>
     <HotelId InternalCode=""></HotelId>
      <Period checkIn="2017-10-26" checkOut="2017-10-28" />
       <RoomInfo>
        <AdultNum RoomType="Twin">2</AdultNum>
         <ChildAges />
       </RoomInfo>
        <flagAvail>Y</flagAvail>
   </SearchHotel_Request>
 </Service_SearchHotel>
------MuhUniqueIdX8nBO7q27yQ1JNb'
,
headers: { 
'Content-Type' :'multipart/form-data; boundary=------MuhUniqueIdX8nBO7q27yQ1JNb',

Also take a look at using the AngularJS Form Data API, how to upload file using Angularjs, multipart/form-data

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.