Question: php->post->proxy->https/https with curl

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
zheng
Forum Newbie
Posts: 1
Joined: Mon Mar 03, 2003 8:43 am

Question: php->post->proxy->https/https with curl

Post by zheng »

hi all,

i get such a question.

I want to post data to a https server throughout a proxy server.

I use fopen() to post data to http server and it works well.

i see many experts use curl to do this so that i install php4.3.1 and wanna give it a try.

the following is my code.. but it does not work..

#-------------------------------------------------

<?php
$http_method = 'https';
$hostname = 'www.mycompany.com';
$link = '/FormRequestListener';

$proxy = 'myproxyserver:8080';
$proxypwd = base64_encode("nick:pwd");

$data_string = "data to be post";

$curl_handle = curl_init ();
curl_setopt ($curl_handle, CURLOPT_URL, $http_method . '://'. $hostname . $link);
curl_setopt ($curl_handle, CURLOPT_PROXY, $proxy);
curl_setopt ($curl_handle, CURLOPT_PROXYUSERPWD, $proxypwd);
//curl_setopt ($curl_handle, CURLOPT_HTTPPROXYTUNNEL,1);
curl_setopt ($curl_handle, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($curl_handle, CURLOPT_POST, 1);
curl_setopt ($curl_handle, CURLOPT_POSTFIELDS, $data_string);
curl_setopt ($curl_handle, CURLOPT_TIMEOUT, 5);

$result = curl_exec ($curl_handle) or die ("There has been an error");

curl_close ($curl_handle);
echo $result;
?>
#-----------------------------------------------------

thanks in advance !
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post by Stoker »

WHat kind of error do you get?

use curl_getinfo(), curl_error() and curl_errno() to get some info..

The main reason I use curl is when I need to do SSL POST, for any GET file() or fopen() would work just fine, if you already have a fopen()/fputs() that does your POST successfully I don't see the big reason for using curl other than education :)
Post Reply