简体   繁体   English

Angular Js使用XML数据发送Http(post)请求

[英]Angular Js send Http (post)request with XML data

I should send HTTP post request to another server from my angular app : 我应该从我的角度应用程序将HTTP发布请求发送到另一台服务器:

$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 : 哪些requestXML是来自google postman Servar上的强制数据,正常返回,但在我的应用中始终返回:

"<?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 . 并给我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 . 我应该如何将requestXML传递到我的帖子数据,因为在将这部分添加到邮递员之前,请确保requestXML ,因为它会返回相同的错误。 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 PS: 'Content-Disposition': 'form-data', **'name':"requestXML",**这部分是我在尝试'Content-Type' :'application/xml',和数据之前从邮递员复制的像: data:'XML Request :<?xml version="1.0" encoding="utf-8"?>........并得到相同的错误

Maybe take a look here: https://groups.google.com/forum/#!topic/rest-assured/QPjllwl8ins 也许在这里看看: 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 本质上,您需要指定内容边界并将该边界放置在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 还要看一下使用AngularJS Form Data API, 如何使用Angularjs上传文件,multipart / form-data

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM