PDA

View Full Version : asp form post and response xml


neontwenty
10-04-2010, 07:49 PM
hi friends
im doing an xm hotel reservation b2c projects where im supposed to
send xml request to the main server and get response in return.
here is a the sample request

<form action="http://www.servername.com/xml_req_parser.php" method="post">
<textarea name="xml" cols="90" rows="20">
<?xml version="1.0" encoding="UTF-8" ?>
<XMLRequest>
<RequestType>DestinationListRequest</RequestType>
<RequestLogin>
<AffiliateCode>AF0001</AffiliateCode>
<AffiliateUsername>myUserName</AffiliateUsername>
<AffiliatePassword>myPassword</AffiliatePassword>
<AffRequestId>5</AffRequestId>
<AffRequestTime><%=now()%></AffRequestTime>
</RequestLogin>
<DestinationListInfo>
<CompleteList>false</CompleteList>
</DestinationListInfo>
</XMLRequest>
</textarea><br>
<input type="submit">
</form>

in return i get the response from http://www.servername.com/xml_req_parser.php
which is the form target.

<?xml version="1.0" encoding="UTF-8" ?>
<XMLResponse>
<ResponseType>HotelListResponse</ResponseType>
<RequestInfo>
<AffiliateCode>AF001</AffiliateCode>
<AffRequestId>5</AffRequestId>
<AffRequestTime>2010-09-30T14:43:24</AffRequestTime>
</RequestInfo>
<TotalNumber>51397</TotalNumber>
<Hotels>
<Hotel>
<HotelCode>ABCDE</HotelCode>
<DestinationId>NFUE</DestinationId>
<Destination>Nice</Destination>
<Country>France</Country>
<HotelName>One Spa Hotel</HotelName>
<StarRating>4</StarRating>
</Hotel>
<Hotel>
<--record 2 here-->
</Hotel>
<Hotel>
<--record 51397 here-->
</Hotel>
</Hotels>
</XMLResponse>

as the response is only after submiting a form how can i load the xml
into my asp program so that i can display the result in web page.
kindly help

neon

Old Pedant
10-05-2010, 01:24 AM
Well, no guarantees, but *SOMETHING* like this:

<%
req = "<?xml version=""1.0"" encoding=""UTF-8"" ?>" & vbNewLine _
& "<XMLRequest>" & vbNewLine _
& "<RequestType>DestinationListRequest</RequestType>" & vbNewLine _
& "<RequestLogin>" & vbNewLine _
& "<AffiliateCode>AF0001</AffiliateCode>" & vbNewLine _
& "<AffiliateUsername>" & Server.URLEncode(user) & "</AffiliateUsername>" & vbNewLine _
& "<AffiliatePassword>" & Server.URLEncode(pwd) & "</AffiliatePassword>" & vbNewLine _
& "<AffRequestId>" & myid & "</AffRequestId>" & vbNewLine _
& "<AffRequestTime>" & now() & "</AffRequestTime>" & vbNewLine _
& "</RequestLogin>" & vbNewLine _
& "<DestinationListInfo>" & vbNewLine _
& "<CompleteList>" & CSTR(completListWanted) & "</CompleteList>" & vbNewLine _
& "</DestinationListInfo>" & vbNewLine _
& "</XMLRequest>"" & vbNewLine

Set http = Server.CreateObject("msxml2.ServerXMLHTTP")
http.Open "POST", "http://www.servername.com/xml_req_parser.php", False
http.Send req

Set xml = Server.CreateObject("Microsoft.XMLDOM")
xml.Load http.ResponseXML
... and then start processing the xml that xmldom object ...
%>

neontwenty
10-05-2010, 08:10 AM
old pedant, thank you for the reply

it failed to load the xml, showing

XML load failed: XML document must have a top level element.

the xml actually having top level element in the response xml that i could see. i assume
it is not get loaded here.

below is the code i wrote

<%
req=request.Form("xml") '// i changed the form ACTION to this page

Set httpObj = Server.CreateObject("msxml2.ServerXMLHTTP")
httpObj.Open "POST", "http://www.servername.com/xml_req_parser.php", False
httpObj.Send req



Set xmlObj = Server.CreateObject("Microsoft.XMLDOM")
'//xmlObj.Load httpObj.ResponseXML
xmlObj.Load httpObj.ResponseXML.xml


if xmlObj.parseError.reason <> "" then
Response.Write "XML load failed: " & xmlObj.parseError.reason & "<br>"
response.end
else
response.Write "load success"
end if

set rootObj=xmlObj.getElementsByTagName("Rooms")

response.Write rootObj.length
%>

Old Pedant
10-05-2010, 06:41 PM
<shrug>Okay, so what does that XML coming back *ACTUALLY* look like?

To find out, replace the line

xmlObj.Load httpObj.ResponseXML.xml

With

Response.Write Replace( httpObj.ResponseText, "<", "&lt;" )
Response.End

I am guessing that you are getting an error message *instead* of XML, so that will tell you.

neontwenty
10-06-2010, 01:37 PM
hi

what i figured out is xmlHttpObj.send doestnt send any xml or the xml is being sent in another format.



below is the simple code i tried



<%
'/////a.asp

xml="<?xml version='1.0' encoding='UTF-8' ?><student><name>abc</name><name>xyz</name></student>"
%>

<form name=form1 action="serverURL/b.asp" method="post">
<textarea name="xml" cols="90" rows="20"><%=xml%></textarea>
<input type="submit">
</form>


<a href="serverURL/b.asp?xml=<%=xml%>" >click</a>

both are working okey,
but below POST gives me A BLANK PAGE in return



<%
'//////c.asp


xml="xml=<?xml version='1.0' encoding='UTF-8' ?><student><name>abc</name><name>xyz</name></student>"


set xmlHttpObj = server.CreateObject("Msxml2.ServerXMLHTTP.6.0")
xmlHttpObj.open "POST", "serverURL/b.asp", false

xmlHttpObj.send xml


'//response.Write xmlHttpObj.status '//gives 200 that is okey


Set xmlDomObj = Server.CreateObject("Msxml2.DOMDocument.6.0")
xmlDomObj.setProperty "ServerHTTPRequest", false
xmlDomObj.async=false


'//xmlDomObj.loadXML xmlHttpObj.responseText
'//response.Write xmlHttpObj.responseText


response.Write replace(xmlHttpObj.responseText, "<", "&lt;" )


%>



<%
'//////b.asp

response.Write request("xml")
%>



what might be the reason?

Old Pedant
10-06-2010, 06:47 PM
Can't begin to guess without the actual URL to test against. Sorry.

*POSSIBLY* it is because you aren't setting something in the request properties to match what the other site is expecting. (e.g., maybe it requires that it get a vald HTTP_USER_AGENT?)

neontwenty
10-09-2010, 07:15 AM
hi old pedant

solved with

xmlHttpObj.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"

thanks for the support