curl problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
thomas
Forum Newbie
Posts: 6
Joined: Wed May 21, 2008 3:18 pm

curl problem

Post 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);
?>
 
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: curl problem

Post 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.
Post Reply