Page 1 of 1

curl problem

Posted: Fri Feb 27, 2009 4:06 pm
by thomas
Hi, I'm trying to convert the perl code below to php. I have some code in php already but it's not working. Can someone help me out. Thanks

perl:

Code: Select all

 
#!/usr/bin/perl
use strict;
use HTTP::Request::Common;
use LWP;
use CGI;
 
$ua = LWP::UserAgent -> new (keep_alive => 1);
 
 
$url = someurl;  
xml = somexml;
 
$req = HTTP::Request->new('POST' => $url);
 
$req -> push_header('Accept' => 'text/xml');
$req -> content_type('text/xml');
$req -> content($xml);
$req -> content_length (length $xml);
$resp = $ua -> request($req);
 
php:

Code: Select all

 
<?php
$url = someurl;
$xml = somexml;
 
$header = array();
$header[] = "Accept: text/xml";
$header[] = "Content-Type: text/xml";
$header[] = "Content-Length: ".strlen($xml)."\r\n";
$header[] = $xml;
 
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD');
 
$output = curl_exec($ch);
?>
 

Re: curl problem

Posted: Fri Feb 27, 2009 4:36 pm
by requinix
You're missing the CURLOPT_POST option.

How is it not working? We can't read minds; if we need to know something then you need to tell us.