| Recommend this page to a friend! |
| PHP HTTP protocol client | > | All threads | > | HTTP POST XML | > | (Un) Subscribe thread alerts |
| |||||||||||||||
I'm trying to use the following code to set the content header to text/xml and POST some XML data to a url. Is this code using http.php correctly to be able to do that? Thanks
<?php require("http.php"); function http_post( $url, $post_values, $leadheaders ) { $returnvalue = ""; set_time_limit(0); $http=new http_class; $http->timeout=0; $http->data_timeout=0; $http->debug=0; $http->html_debug=0; $http->follow_redirect=1; $http->user_agent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"; $error=$http->GetRequestArguments($url,$arguments); $arguments["RequestMethod"]="POST"; $arguments["PostValues"]=$post_values; $arguments["Headers"]=$leadheaders; $error=$http->Open($arguments); if($error) die($error); $error=$http->SendRequest($arguments); if($error) die($error); $headers=array(); $error=$http->ReadReplyHeaders(&$headers); if($error) die($error); for(;;) { $error=$http->ReadReplyBody($body,1000); if ($error!="" || strlen($body)==0) break; $returnvalue .= $body; } return $returnvalue; } $lead = "<?xml version=\"1.0\" encoding=\"utf-8\"?> <!DOCTYPE wshRequest SYSTEM \"http://wwwstage.domainname.com/DTD/wshRequest.dtd\"> <wshRequest> <type>Order</type> <proxyUserId>xmlGSM</proxyUserId> <partner> <name>DirectAgents</name> <uniqueId>58A0AB51-CBDA-4F36-B071-257AA3171DC1</uniqueId> <password>drePR3thew</password> </partner> <customer> <firstName>Susan</firstName> <lastName>Brown</lastName> <email>[email protected]</email> </customer> <serviceAddress> <addressLine1>1234 SusanBrown Avenue</addressLine1> <city>Chicago</city> <state>IL</state> <zip>60208</zip> <firstName>Susan</firstName> <lastName>Brown</lastName> <phone1area>714</phone1area> <phone1exch>999</phone1exch> <phone1suffix>2000</phone1suffix> </serviceAddress> <order> <item> <productName>Home Warranty Lead</productName> <property> <name>adName</name> <value>DAMicrosite_GSM</value> </property> <property> <name>oiPropLeadPlacementBrand</name> <value>AH</value> </property> <property> <name>oiPropResponseVehicle</name> <value>online</value> </property> <property> <name>oiPropResultsEntity</name> <value>NCD</value> </property> </item> </order> </wshRequest>"; $leadheaders = array( "Content-Type" => "text/xml", "Content-Length" => mb_strlen($lead, '8bit')); $leadarray = array( $lead ); $body = http_post( "http://wwwstage.domainname.com/partnerInterface/wshRequest.jsp", $leadarray , $leadheaders); echo( $body ); so when I use this code I get this response back. <?xml version="1.0" encoding="utf-8" standalone="yes" ?> <!DOCTYPE wshResponse [ <!ELEMENT wshResponse (resultCode, resultMessage, processCode, processMessage, orderNumber?, subtotal?, estimatedTax?, shipping?, totalPrice?, totalPromo?, recurringSubtotal?, verazipreply?, orderItemInfo*) > <!ELEMENT resultCode (#PCDATA) > <!ELEMENT resultMessage (#PCDATA) > <!ELEMENT processCode (#PCDATA) > <!ELEMENT processMessage (#PCDATA) > <!ELEMENT orderNumber (#PCDATA) > <!ELEMENT subtotal (#PCDATA) > <!ELEMENT estimatedTax (#PCDATA) > <!ELEMENT shipping (#PCDATA) > <!ELEMENT totalPrice (#PCDATA) > <!ELEMENT totalPromo (#PCDATA) > <!ELEMENT recurringSubtotal (#PCDATA) > <!-- Sears Verazip Information --> <!ELEMENT verazipreply (customernum, verazipreturnedrows, veraziptable+) > <!ELEMENT customernum (#PCDATA) > <!ELEMENT verazipreturnedrows (#PCDATA) > <!ELEMENT veraziptable (verazipstate, verazipstatetx, verazipzip1, verazipzip2, geocode, verazipzipext1, verazipzipext2, verazipcity, countycode, countyname, inoutcitylimits) > <!ELEMENT verazipstate (#PCDATA) > <!ELEMENT verazipstatetx (#PCDATA) > <!ELEMENT verazipzip1 (#PCDATA) > <!ELEMENT verazipzip2 (#PCDATA) > <!ELEMENT geocode (#PCDATA) > <!ELEMENT verazipzipext1 (#PCDATA) > <!ELEMENT verazipzipext2 (#PCDATA) > <!ELEMENT verazipcity (#PCDATA) > <!ELEMENT countycode (#PCDATA) > <!ELEMENT countyname (#PCDATA) > <!ELEMENT inoutcitylimits (#PCDATA) > <!ELEMENT orderItemInfo (productName, trackingNumber, provider?) > <!-- Provider information --> <!ELEMENT provider (brand, branchNumber, phone, city, state, zip) > <!ELEMENT brand (abbreviation, name) > <!-- Address information --> <!ELEMENT city (#PCDATA) > <!ELEMENT state (#PCDATA) > <!ELEMENT zip (#PCDATA) > <!-- Phone information --> <!ELEMENT phone (areaCode, exchange, suffix, extension?) > <!ELEMENT areaCode (#PCDATA) > <!ELEMENT exchange (#PCDATA) > <!ELEMENT suffix (#PCDATA) > <!ELEMENT extension (#PCDATA) > <!-- Misc supporting elements --> <!ELEMENT productName (#PCDATA) > <!ELEMENT trackingNumber (#PCDATA) > <!ELEMENT abbreviation (#PCDATA) > <!ELEMENT name (#PCDATA) > <!ELEMENT branchNumber (#PCDATA) > ]> <wshResponse> <resultCode>2</resultCode> <resultMessage>The XML request is malformed.</resultMessage> <processCode>0</processCode> <processMessage><![CDATA[Fatal Error encountered at line: 1 of URI: null. Message: Content is not allowed in prolog.]]></processMessage> </wshResponse>
I don't think that is the way the server expects the data. I think the XML request data is expected in the request body. Try using the Body parameter instead of PostValues. Take a look at the test_http_soap.php script for an example.
I agree with Manuel Lemos.The XML data is expected in the request body.
I suspect that what you really want to do is to send the XML as POST body not as a POST value.
In that case you need to use the Body parameters instead of PostValues. Take a look at the test_http_soap.php example script for an example of how to do that. |
info at phpclasses dot org.
