PHP https post XML data with cURL -


i'm trying send https post request xml data server using php.

anything sends server requires authentication therefore i'll use curl.

some background info.: xml data request server upload file specific url local storage.

one rule of using api must set content type each request application/xml.

this i've done isn't working...

<?php $fields = array( 'data'=>'<n1:asset xmlns:n1="http://.....com/"><title>aaaa</title><filename>http://192.168.11.30:8080/xxx.html</filename><description>aaaa_desc</description><filetype>html</filetype></n1:asset>' ); $fields_string = ""; foreach($fields $key=>$value) { $fields_string .= $key.'='.$value.'&'; } rtrim($fields_string,'&');  $url = "https://192.168.11.41:8443/";  $ch = curl_init(); curl_setopt($ch, curlopt_url, $url); curl_setopt($ch, curlopt_post, count($fields)); curl_setopt($ch, curlopt_postfields, $fields_string); curl_setopt($ch, curlopt_ssl_verifypeer, false); curl_setopt($ch, curlopt_ssl_verifyhost, false);  curl_setopt($ch, curlopt_header, true); curl_setopt($ch, curlopt_returntransfer, true); curl_setopt($ch, curlopt_userpwd, "admin:12345678"); curl_setopt($ch, curlopt_httpheader, array('content-type: application/xml', 'content-length: '. strlen($fields_string)) );  $result = curl_exec( $ch );  curl_close($ch);   echo $result; ?> 

i expected xml reply of either upload successful or upload failed. instead getting error message.

http/1.1 415 unsupported media type server: apache-coyote/1.1 content-type: text/xml;charset=utf-8 content-length: 0 date: thu, 02 dec 2010 03:02:33 gmt

i'm sure file type correct, xml format correct. i've tried urlencode fields didn't work. else might have done wrong?

i solve with

$xml = $this->getxml(); $url = $this->geturl(); $ch = curl_init(); curl_setopt($ch, curlopt_url, $url); curl_setopt($ch, curlopt_header, 1); curl_setopt($ch, curlopt_ssl_verifypeer, 0); curl_setopt($ch, curlopt_ssl_verifyhost, 0); curl_setopt($ch, curlopt_returntransfer, 1); curl_setopt($ch, curlopt_customrequest, 'post'); curl_setopt($ch, curlopt_post, 1); curl_setopt($ch, curlopt_postfields, $xml); curl_setopt($ch, curlopt_httpheader, array(                                        'content-type: application/xml',                                         'content-length: ' . strlen($xml)                                      )); $output = curl_exec($ch); curl_close($ch); 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -