downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

http_put_data> <http_post_data
[edit] Last updated: Fri, 25 May 2012

view this page in

http_post_fields

(PECL pecl_http >= 0.10.0)

http_post_fieldsエンコードされる前のデータを使用して POST リクエストを実行する

説明

string http_post_fields ( string $url , array $data [, array $files [, array $options [, array &$info ]]] )

指定した url に対して HTTP POST リクエストを実行します。

リクエストのオプション を参照ください。

パラメータ

url

URL。

data

POST する値の連想配列。

files

POST するファイルの配列。

options

リクエストのオプション

info

リクエスト/レスポンス の情報

返り値

成功した場合は HTTP レスポンスを文字列で、失敗した場合は FALSE を返します。

例1 http_post_fields() の例

<?php
$fields 
= array(
    
'name' => 'mike',
    
'pass' => 'se_ret'
);
$files = array(
    array(
        
'name' => 'uimg',
        
'type' => 'image/jpeg',
        
'file' => './profile.jpg',
    )
);

$response http_post_fields("http://www.example.com/"$fields$files);
?>



http_put_data> <http_post_data
[edit] Last updated: Fri, 25 May 2012
 
add a note add a note User Contributed Notes http_post_fields
dionmagnus at yandex dot ru 19-Feb-2010 04:11
Hear is an axmaple how to arrays as POST varibles:
<?php
 
  $response
= http_post_fields('http://example.com/page.php',
                                array(
'val[0]'=>'val1', 'val[1]'=>'val2'));
 
                               
  echo
"\$response: $response\n";                               
                               
?>
ya at kirilloid dot ru 02-Mar-2008 07:59
comment to wormholio's answer:
if you use regular expression, then use it fully:
"/HTTP\/\d\.\d 302 Found/"
Some servers still can use HTTP 1.0
wormholio at gmail dot com 28-Jan-2008 07:32
To use POST to submit a form to a site which requires a cookie for authentication you put the cookie in the $options array.  Example:

<?php

$auth
="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

$form_url="http://pirates.spy-hill.net/forum_reply.php?thread=663";

$message  = "RoboCodeDwarf now has the gold. \n\n";
$message .= "RoboCodeDwarf sez: [quote] " . `fortune -s` . "[/quote]\n";

$form_fields = array(
                    
'content' => $message,
                    
'add_signature' => 'add_it',
                    
'submit' => 'Post reply'  );
$form_files=array();
$form_options=array( 'cookies' => array( 'auth' => $auth ) );

$response = http_post_fields($form_url, $form_fields, $form_files, $form_options );

$n = preg_match("/HTTP\/1.1 302 Found/", $response, $matches);
if(
$n<1) echo "FAILED\n";
 else    echo
"POSTED\n";

?>
thomasxholder at compuserve dot de 07-Jan-2007 03:21
It was hard to figure out how to actually post files with this function. The "Array of files to post" is an array of associative arrays, each need the keys "name", "type" and "file". Consider this example code:

<?php
$files
= array(
    array(
       
'name' => 'somename',
       
'type' => 'text/plain',
       
'file' => $filename
   
)
);
$http_response = http_post_fields($url, $data, $files);
?>

 
show source | credits | stats | sitemap | contact | advertising | mirror sites