You are here: Re: [PHP] Problem with fopen and sending POST vars « PHP « IT news, forums, messages
Re: [PHP] Problem with fopen and sending POST vars

Posted by tg-php on 12/20/05 18:16

There are a couple examples of manually sending POST data via fsockopen() on:

http://us2.php.net/manual/en/function.fsockopen.php


Basically the stucture is the same as URL "GET" variables but you have to send the header data manually and set content-type to "application/x-www-form-urlencoded". But you still end up sneding data in this form: "var1=value1&var2=value2&var3=value3" (hence the "urlencoded" part).

Good luck!

-TG

= = = Original message = = =

Hello everyone!

I have a problem sending POST vars via fopen.
It was possible for me to send some xml data but that's all.

Anyone know how to send POST vars?
Big probleme here is also that i have to connect via SSL.

Many thanks for any help.

Greetings
~Barry

Here is my code:
<?
# generating xml for testing
$request_data = "<xml><data>blablubb</data></xml>";

# array with the options to create stream context
$opts = Array();

# compose HTTP request header
$header .= "User-Agent: PHP Script\\r\\n";
$header .= "Content-Type: text/xml\\r\\n";
$header .= "Content-Length: ".strlen($request_data)."\\r\\n";
$header .= "Connection: close";

# define context options for HTTP request
$opts['http']['method'] = 'POST';
$opts['http']['header'] = $header;
$opts['http']['content'] = $request_data;

# create stream context
$context = stream_context_create($opts);

$fp = fopen
("https://easy-demo.tcinternet.de/hosting/servlet/Dispatcher","r",false,$context);
if (!$fp) echo "error";
else

$vars= explode ("&",stream_get_contents($fp));
foreach ($vars as $key => $value)

$var = explode ("=", $value);
$tcph[$var[0]] = urldecode($var[1]);


print_r($tcph);
?>


___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация