curl-and-php
Re: How i can use curl option instead php fputs function?
Date: Mon, 10 Mar 2003 12:25:23 +0100
hi
If the form is of type multipart/form-data you should make an array and use CUROPT_POSTFIELDS with that array. for example .. $data['email']="blala"; $data['name']="blabla"; and so on.
if the form is of normal kind you just make a string like this: $data = "email=blala&name=blabla";
And then:
curl_setopt($ch, CURLOPT_URL, "url");
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_REFERER,"someurl");
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 3); //times out after 4s
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
and then curl_exec($ch);
/Per Sandberg
----- Original Message -----
From: "AzKar" <azkar_at_hotbox.ru>
To: <curl-and-php_at_lists.sourceforge.net>
Sent: Monday, March 10, 2003 5:14 AM
Subject: How i can use curl option instead php fputs function?
> Hi all,
>
> My hoster just disallow socket operation by fsocketopen and etc. Early i use
> script which use above function for connection to some servers API. Part of
> code is here:
>
> $fp = fsockopen(server, port, $errno, $errstr, 90);
>
> fputs($fp, $xml);
> while(1)
> {
> $line = fgets($fp);
> $result .= $line;
> if(ereg("</epp>$", $result))
> {
> break;
> }
> }
> For connecting to target server i use this code:
>
> $ch = curl_init();
> curl_setopt ($ch, CURLOPT_TIMEOUT, 90);
> curl_setopt ($ch, CURLOPT_URL,"server:port");
> curl_setopt ($ch, CURLOPT_HEADER, 0);
> ob_start();
> $result=curl_exec ($ch);
> ob_end_clean();
> curl_close ($ch);
>
> And it work well for me.
>
> I tried use curl post function instead fputs, but hasn't good result,
> because target servers not receive required strings.
> I try curl "put" option (putting data from file) and also haven't good
> result, target server just loss connect.Could anyone give me idea, how i can
> do it fputs by curl?
> Thanking in advance
>
> Azer
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Etnus, makers of TotalView, The debugger
> for complex code. Debugging C/C++ programs can leave you feeling lost and
> disoriented. TotalView can help you find your way. Available on major UNIX
> and Linux platforms. Try it free. www.etnus.com
>
>
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
Received on 2003-03-10