Re: post xml
| From: | qt | Date: | Mon, 03 Mar 2003 16:07:17 +0000 |
| Subject: | Re: post xml | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-137926@lists.php.net to get a copy of this message | ||
Dear Sirs,
I am trying to post xml file to http address but no result. I saw your
script at the below but I can not understand How can send file? Can you help
Best Regards
"Mincu Alexandru" <alex@intelinet.ro> wrote in message
news:1046360758.4855.7.camel@alex.local.intelinet.ro...
> yes you can connect to the server from your PHP script and send a post
> request .. here is a function that would help:
>
> --- PHP --
>
> function http_post($server, $port, $url, $vars) {
> // example:
> // http_post(
> // "www.fat.com",
> // 80,
> // "/weightloss.pl",
> // array("name" => "obese bob", "age" =>
> "20")
> // );
>
> $urlencoded = "";
> while (list($key,$value) = each($vars))
> $urlencoded.= urlencode($key) . "=" . urlencode($value) . "&";
> $urlencoded = substr($urlencoded,0,-1);
> $content_length = strlen($urlencoded);
> $headers = "POST $url HTTP/1.1
> Accept: text/plain, text/html, text/xml, image/gif, image/jpeg,
> image/png, image/bmp
> Accept-Charset: UTF-8
> Accept-Language: en
> Content-Length: $content_length
> Cache-Control: no-cache
> Content-Type: application/x-www-form-urlencoded
> Host: $server
> User-Agent: Panasonic-GAD67/1.0 UP.Browser/5.0.3.5 (GUI)
> Connection: Keep-Alive
>
> ";
> $fp = fsockopen($server, $port, $errno, $errstr);
> if (!$fp) {
> return false;
> }
> fputs($fp, $headers);
> fputs($fp, $urlencoded);
>
> $ret = "";
> while (!feof($fp))
> $ret.= fgets($fp, 1024);
> fclose($fp);
> return $ret;
> }
>
> --- /PHP ---
>
> You can change the headers if you like ...
>
> Hope it helps.
> --
> Mincu Alexandru intelinet.ro
> Tel:+4 0745 369719 +4 021 3140021
> www.intelinet.ro office@intelinet.ro
>
>