fjckls Posted October 27, 2011 Report Share Posted October 27, 2011 (edited) Man jānosūta xml uz serveri un tad attiecīgi serveris atgriež man xml, bet kautkas man te nestrādā, jo visu laiku met ārā "Bad Request - Invalid URL" Te būs mans kods: $url = "http://www.domeens.com"; $xml = '<?xml version="1.0" encoding="UTF-8"?> <Request> <Tags>blah blah</Tags> </Request>'; $header = "POST HTTP/1.1 \r\n"; $header .= "Content-type: text/xml \r\n"; $header .= "Content-length: ".strlen($xml)." \r\n"; $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 4); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header); $data = curl_exec($ch); if(curl_errno($ch)) print curl_error($ch); else curl_close($ch); echo $data; Lai viss parezi darbotos, šāds ir servera nosacījumi: - Requests to the server should be sent as XML over HTTP 1.1 - The request type should be POST; - A Content-Length header should be present, and the total length of the request should be below 16KB; - A Content-Type header should be present, containing the media type value text/xml; Edited October 27, 2011 by fjckls Quote Link to comment Share on other sites More sharing options...
fjckls Posted October 27, 2011 Author Report Share Posted October 27, 2011 Nu beidzot sanāca, hvz vai šitais ir tas pareizākais veids, bet nu strādā vismaz :): $url = "http://www.domeens.com"; $xml = '<?xml version="1.0" encoding="UTF-8"?><Request><Tags>blah blah</Tags></Request>'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); curl_setopt($ch,CURLOPT_HTTPHEADER, array('Content-type:text/xml')); $data = curl_exec($ch); if(curl_errno($ch)) print curl_error($ch); else curl_close($ch); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.