Send HTTP Post with Array - PHP

jaihiori

New Member
I'm trying to use this nice function:\[code\]function do_post_request($url, $data, $optional_headers = null) { $params = array('http' => array( 'method' => 'POST', 'content' => $data )); if ($optional_headers !== null) { $params['http']['header'] = $optional_headers; } $ctx = stream_context_create($params); $fp = @fopen($url, 'rb', false, $ctx); if (!$fp) { throw new Exception("Problem with $url, $php_errormsg"); } $response = @stream_get_contents($fp); if ($response === false) { throw new Exception("Problem reading data from $url, $php_errormsg"); } return $response;}\[/code\]to send a POST command to a specific url, my problem is i'm trying to send the post paramters in a form of an array, something like this\[code\]login[username]: myusernamelogin[password]: mypassword,\[/code\]however i'm not able to do that, calling the function with :\[code\] $login_post = array('login[username]' => $email, 'login[password]' => ''); do_post_request(getHost($website['code']), $login_post);\[/code\]always send the data to the post in the form:\[code\]username: myusernamepassword: mypassword\[/code\]How can I avoid this (without using curl)? Thanks a lot.ThanksYehia
 
Back
Top