Я пытаюсь опубликовать строку xml в удаленном сценарии perl через cURL.Я хочу, чтобы строка xml была опубликована как параметр сообщения «myxml».См. Код, который я использую ниже:
$url = 'http://myurl.com/cgi-bin/admin/xml/xml_append_list_init.pl';
$xml = '<?xml version="1.0" standalone="yes"?>
<SUB_appendlist>
<SUB_user>username</SUB_user>
<SUB_pass>password</SUB_pass>
<list_id>129</list_id>
<append>
<subscriber>
<address>test@test.comk</address>
<first_name>Test</first_name>
<last_name>Test</last_name>
</subscriber>
</append>
</SUB_appendlist>';
$ch = curl_init(); //initiate the curl session
curl_setopt($ch, CURLOPT_URL, $url); //set to url to post to
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // tell curl to return data in a variable
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml", "Content-length: ".strlen($xml)));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'myxml='.urlencode($xml)); // post the xml
curl_setopt($ch, CURLOPT_TIMEOUT, (int)30); // set timeout in seconds
$xmlResponse = curl_exec($ch);
curl_close ($ch);
Однако удаленный сервер не видит данные в параметре «myxml».И я получаю следующий ответ обратно в $ xmlResponse
HTTP/1.1 200 OK
Date: Fri, 15 Apr 2011 12:00:44 GMT
Server: Apache/2.2.9 (Debian)
Vary: Accept-Encoding
Content-Length: 0
Content-Type: text/html; charset=ISO-8859-1
. Я ни в коем случае не эксперт cURL, поэтому я могу что-то делать в запросе mu cURL, что явно неправильно.Был бы признателен, если кто-нибудь может пролить свет или заметить какие-либо проблемы в этом.Надеюсь, этого достаточно.
Ура, Адриан.