Posting simpleXML data to server

Hi

I have a simpleXML object called $xml.

I need to post this to a remote server.

What is the best way to do this?

I am trying with Curl. But I get a “couldn’t connect to host” error.

I want to connect to (not actual server):
http://testing.cashedup.com:13468/XMLImport/
If I visit that in the browser (well the actual server) it resolves quickly.
However, the following:


$post_data = 'xmlData=' . trim($xml->asXML());
$ch = curl_init("http://testing.cashedup.com:13468/XMLImport/");	
	curl_setopt($ch, CURLOPT_TIMEOUT,30);	
	curl_setopt($ch, CURLOPT_POST,1);
	curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data);
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1); 
	curl_setopt($ch, CURLOPT_HEADER,0);  // DO NOT RETURN HTTP HEADERS 
	curl_setopt($ch, CURLOPT_RETURNTRANSFER  ,1);  // RETURN THE CONTENTS OF THE CALL
	$result = curl_exec($ch);
	print_r(curl_getinfo($ch));
		echo curl_errno($ch) . '-' .
        curl_error($ch);
	curl_close($ch);

The error:

Array (  => http://testing.cashedup.com:13468/XMLImport/ [content_type] => [http_code] => 0 [header_size] => 0 [request_size] => 0 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 29.996183 [namelookup_time] => 0.002145 [connect_time] => 0 [pretransfer_time] => 0 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => -1 [upload_content_length] => -1 [starttransfer_time] => 0 [redirect_time] => 0 ) 7-couldn't connect to host[]

Thanks

Curl should do the trick.

Could be a firewall or blocked outgoing ports on the server blocking your request. You can always try the request from a different network (like your home network)

I tried this as a simple test case


$ch = curl_init();
 
 curl_setopt($ch, CURLOPT_URL,"http://www.google.com.au/");
 curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
 curl_setopt($ch, CURLOPT_FAILONERROR, 1); 
 curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable 
 curl_setopt($ch, CURLOPT_TIMEOUT, 3); // times out after 4s 
 curl_setopt($ch, CURLOPT_POST, 1); // set POST method 
 curl_setopt($ch, CURLOPT_POSTFIELDS, "q=hello+world");
 curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0);
 print_r(curl_getinfo($ch));
		echo curl_errno($ch) . '-' .
        curl_error($ch);
 
 
 $result =curl_exec ($ch);
 curl_close ($ch); 
 echo "[".$result; 

And the result was:


Array
(
     => http://www.google.com.au/
    [content_type] => 
    [http_code] => 0
    [header_size] => 0
    [request_size] => 0
    [filetime] => 0
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 0
    [namelookup_time] => 0
    [connect_time] => 0
    [pretransfer_time] => 0
    [size_upload] => 0
    [size_download] => 0
    [speed_download] => 0
    [speed_upload] => 0
    [download_content_length] => -1
    [upload_content_length] => -1
    [starttransfer_time] => 0
    [redirect_time] => 0
)


I am not sure if my code is broke or my server doesn’t allow curl.
Could somebody test this quick Google search curl to see what they get?

Thanks

I think your curl_getinfo needs to come after curl_exec