Отпровляю post запрос через сURL xml .Когда указываю параметр curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));или aplication/xml.Запрос вообще не отпровляется на сервер.Если не узать CURLOPT_HTTPHEADER, то xml приходит как массив [<?xml version="1.0" encoding]"UTF-8" ?> <priceRequest><customerNo>123</customerNo><password>abc</password><skuList><SKU>. Как отослать xml чтобы на сервере его согли распарсить . код $xml_data = '<?xml version="1.0" encoding="UTF-8" ?> <priceRequest><customerNo>123</customerNo><password>abc</password><skuList><SKU>99999</SKU><lineNumber>1</lineNumber></skuList></priceRequest>'; $URL = "https://test.testserver.com/PriceAvailability"; $ch = curl_init($URL); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml')); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); curl_close($ch); print_r($output); |
1 answer
$xml_data = '<?xml version="1.0" encoding="UTF-8" ?> <priceRequest><customerNo>123</customerNo><password>abc</password><skuList><SKU>99999</SKU><lineNumber>1</lineNumber></skuList></priceRequest>'; $URL = "https://test.testserver.com/PriceAvailability"; $headers = array( "Content-type: text/xml", "Content-length: " . strlen($xml_data), "Connection: close", ); $ch = curl_init($URL); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); curl_close($ch); - I tried already in quotes and without - Stanzlav Surtkov
- @ SurtkovStanislav edited the answer, try the same - InDevX
- I measure the server if ($ _ POST) {file_put_contents ("logs.log", $ _POST, FILE_APPEND); print_r ($ _ POST); } In response, I get "1.0" encoding = "UTF-8"?> <PriceRequest> <customerNo> 123 </ customerNo> <password> abc </ password> <skuList> <SKU> 99999 </ SKU> <lineNumber> 1 </ lineNumber> </ skuList> </ priceRequest> If I specify curl_setopt ($ ch, CURLOPT_HTTPHEADER, $ headers); post is not otpravlyaetsya - Stanzlav Surtkov
- did not help, did uvas work? - Surtkov Stanislav
- There is nothing that does not work - Surtkov Stanislav
|