Php http post fields

http_post_fields

Returns the HTTP response(s) as string on success, or FALSE on failure.

Примеры

Пример #1 A http_post_fields() example

$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 );
?>

Последние поступления:

Размещена 10 августа 2020 года

Я по ТВ видел, что через 10 лет мы будем жить лучше, чем в Германии.
Я не понял, что это они с Германией сделать хотят?!

ТехЗадание на Землю

Размещена 14 марта 2018 года

Пpоект Genesis (из коpпоpативной пеpеписки)

Шпаргалка по работе с Vim

Размещена 05 декабря 2017 года

Vim довольно мощный редактор, но работа с ним не всегда наглядна.
Например если нужно отредактировать какой-то файл например при помощи crontab, без знания специфики работы с viv никак.

Ошибка: Error: Cannot find a valid baseurl for repo

Размещена 13 сентабря 2017 года

Если возникает ошибка на centos 5 вида
YumRepo Error: All mirror URLs are not using ftp, http[s] or file.
Eg. Invalid release/

Linux Optimization

Размещена 30 июля 2012 года

Источник

http_post_fields

Returns the HTTP response(s) as string on success, or FALSE on failure.

Examples

Example #1 A http_post_fields() example

$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 );
?>

User Contributed Notes 4 notes

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:

$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» ;

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:

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

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

Hear is an axmaple how to arrays as POST varibles:

$response = http_post_fields ( ‘http://example.com/page.php’ ,
array( ‘val[0]’ => ‘val1’ , ‘val[1]’ => ‘val2’ ));

  • HTTP Functions
    • http_​cache_​etag
    • http_​cache_​last_​modified
    • http_​chunked_​decode
    • http_​deflate
    • http_​inflate
    • http_​build_​cookie
    • http_​date
    • http_​get_​request_​body_​stream
    • http_​get_​request_​body
    • http_​get_​request_​headers
    • http_​match_​etag
    • http_​match_​modified
    • http_​match_​request_​header
    • http_​support
    • http_​negotiate_​charset
    • http_​negotiate_​content_​type
    • http_​negotiate_​language
    • ob_​deflatehandler
    • ob_​etaghandler
    • ob_​inflatehandler
    • http_​parse_​cookie
    • http_​parse_​headers
    • http_​parse_​message
    • http_​parse_​params
    • http_​persistent_​handles_​clean
    • http_​persistent_​handles_​count
    • http_​persistent_​handles_​ident
    • http_​get
    • http_​head
    • http_​post_​data
    • http_​post_​fields
    • http_​put_​data
    • http_​put_​file
    • http_​put_​stream
    • http_​request_​body_​encode
    • http_​request_​method_​exists
    • http_​request_​method_​name
    • http_​request_​method_​register
    • http_​request_​method_​unregister
    • http_​request
    • http_​redirect
    • http_​send_​content_​disposition
    • http_​send_​content_​type
    • http_​send_​data
    • http_​send_​file
    • http_​send_​last_​modified
    • http_​send_​status
    • http_​send_​stream
    • http_​throttle
    • http_​build_​str
    • http_​build_​url

    Источник

    http_post_fields

    Возвращает строку с HTTP-ответом(ами) при успешном завершении работы, или FALSE при ошибке.

    Примеры

    Пример #1 Пример использования http_post_fields()

    $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 );
    ?>

    User Contributed Notes 4 notes

    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:

    $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» ;

    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:

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

    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

    Hear is an axmaple how to arrays as POST varibles:

    $response = http_post_fields ( ‘http://example.com/page.php’ ,
    array( ‘val[0]’ => ‘val1’ , ‘val[1]’ => ‘val2’ ));

Оцените статью