php通過header傳送自定義資料方法

2022-09-28 09:57:10 字數 1966 閱讀 6638

本文將介紹如何通過header傳送自定義資料。傳送請求時,除了可以使用$_get/$_post傳送資料,也可以把資料放在header中傳輸過去。

傳送header:

我們定義了三個引數,token、language、region,放入header傳送過去

php$url = '';

$header = array('token:jxrazez**m3hxm3d9pwnyiqqqc1sjbsu','language:zh','region:gz');

$content = array(

'name' => 'fdipzone'

);$response = tocurl($url, $header, $content);

$data = json_decode($response, true);

echo 'post data:';

echo '程式設計客棧e>';

print_r($data['post']);

echo '';

echo 'header data:';

echo '';

print_r($data['header']);

echo '';

/** * 傳送資料

* @param string $url 請求的位址

* @param array $header 自定義的header資料

* @param array $content post的資料

接收header

我們可以在$_server中獲取header資料,自定義的資料都是使用http_作為字首的,所以可以把http_字首的資料讀出。

<?php $post_data = $_post;

$header = get_all_headers();

$ret = array();

$ret['post'] = $post_data;

$ret['header'] = $header;

header('content-type:application/json;charset=utf8');

echo json_encode($ret, json_unescaped_unicode|json_pretty_print);

/** * 獲取自定義的header資料

*/function get_all_headers()

}} return $headers;

}?>

輸出:post data:

array

( [name] => fdipzone

)header data:

array

( [token] => jxrazez**m3hxm3d9pwnyiqqqc1sjbsu

[language] => zh

[region] => gz

)本文標題: php通過header傳送自定義資料方法

本文位址: /wangluo/php/218078.html

php常用header狀態

200 正常狀態 301 永久重定向,記得在後面要加重定向位址 location url 重定向,其實就是302 暫時重定向 header location 設定頁面304 沒有修改 顯示登入框,header www authenticate basic realm 登入資訊 echo 顯示的資訊!...

php常見header狀態

200 正常狀態 301 永久重定向,記得在後面要加重定向位址 location url 重定向,其實就是302 暫時重定向 header location 設定頁面304 沒有修改 顯示登入框,header www authenticate basic realm 登入資訊 echo 顯示的資訊!...

php 通過sendcloud傳送郵件 附件功能

function send mail 配置檔案 method post 郵件傳送必須是post header content type multipart form data boundary mime boundary eol,content data context stream context...