欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

php請求數(shù)據(jù)的方式,php請求數(shù)據(jù)的方式有哪些

php請求第三方數(shù)據(jù)方法

方法有很多,其中有file_get_contents把數(shù)據(jù)讀到一個字符串中,還有一個是curl方式,兩種方式有所不同,查一下就知道區(qū)別了

創(chuàng)新互聯(lián)專注于郟縣網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗。 熱誠為您提供郟縣營銷型網(wǎng)站建設(shè),郟縣網(wǎng)站制作、郟縣網(wǎng)頁設(shè)計、郟縣網(wǎng)站官網(wǎng)定制、小程序開發(fā)服務(wù),打造郟縣網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供郟縣網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。

php中有哪些常用的遠(yuǎn)程請求發(fā)送方法

1、用file_get_contents 以get方式獲取內(nèi)容:

?php

$url = '' ;

$html = file_get_contents ( $url );

echo $html ;

?

2、用fopen打開url,用get方式獲取

$fp = fopen ( $url , 'r' );

stream_get_meta_data( $fp );

while (! feof ( $fp )) {

$result .= fgets ( $fp , 1024);

}

echo "url body: $result" ;

fclose( $fp );

3、用file_get_contents 以post方式獲取內(nèi)容:

$data = array ( 'foo' = 'bar' );

$data = http_build_query($data);

$opts = array (

'http' = array (

'method' = 'POST' ,

'header' = "Content-type: application/x-www-form-urlencodedrn" . 'Content-Length: ' . strlen($data) . 'rn' , 'content' = $data ) ); $context = stream_context_create($opts); $html = file_get_contents( '' , false , $context); echo $html;

4、用fsockopen函數(shù)打開url,以get方式獲取完整的數(shù)據(jù),包括header和body,fsockopen需要 PHP.ini 中 allow_url_fopen 選項開啟

function get_url ( $url , $cookie =false)

{

$url = parse_url ( $url );

$query = $url [path]. '?' . $url [query];

echo 'Query:' . $query ;

$fp = fsockopen ( $url [host], $url [port]? $url [port]:80 , $errno , $errstr , 30);

if (! $fp ) {

return false;

} else {

$request = 'GET $query HTTP/1.1rn' ;

$request .= 'Host: $url[host]rn' ;

$request .= 'Connection: Closern' ;

if ( $cookie ) $request .= 'Cookie: $cookien' ;

$request .= 'rn' ;

fwrite( $fp , $request );

while (!@ feof ( $fp )) {

$result .= @ fgets ( $fp , 1024);

}

fclose( $fp );

return $result ;

}

}

//獲取url的html部分,去掉header

function GetUrlHTML( $url , $cookie =false)

{

$rowdata = get_url( $url , $cookie );

if ( $rowdata )

{

$body = stristr ( $rowdata , 'rnrn' );

$body = substr ( $body ,4, strlen ( $body ));

return $body ;

}

return false;

}

5、 用fsockopen函數(shù)打開url,以POST方式獲取完整的數(shù)據(jù),包括header和body

function HTTP_Post( $URL , $data , $cookie , $referrer = '' )

{

// parsing the given URL

$URL_Info = parse_url ( $URL );

// Building referrer

if ( $referrer == '' ) // if not given use this script as referrer

$referrer = '111' ;

// making string from $data

foreach ( $data as $key = $value )

$values []= '$key=' .urlencode( $value );

$data_string =implode( '' , $values );

// Find out which port is needed – if not given use standard (=80)

if (!isset( $URL_Info [ 'port' ]))

$URL_Info [ 'port' ]=80;

// building POST-request:

$request .= "POST " . $URL_Info [ 'path' ]. " HTTP/1.1n" ; $request .= "Host: " . $URL_Info [ 'host' ]. "n" ; $request .= "Referer: $referern" ; $request .= "Content-type: application/x-www-form-urlencodedn" ; $request .= 'Content-length: ' . strlen ( $data_string ). "n" ; $request .= 'Connection: closen' ; $request .= 'Cookie: $cookien' ; $request .= 'n' ; $request .= $data_string . 'n' ; $fp = fsockopen ( $URL_Info [ 'host' ], $URL_Info [ 'port' ]); fputs ( $fp , $request ); while (! feof ( $fp )) { $result .= fgets ( $fp , 1024); } fclose( $fp ); return $result ;

}

6、 使用curl庫,使用curl庫之前,可能需要查看一下php.ini是否已經(jīng)打開了curl擴展

$ch = curl_init();

$timeout = 5;

curl_setopt ( $ch , CURLOPT_URL, ‘http: //');

curl_setopt ( $ch , CURLOPT_RETURNTRANSFER, 1);

curl_setopt ( $ch , CURLOPT_CONNECTTIMEOUT, $timeout );

$file_contents = curl_exec( $ch );

curl_close( $ch );

echo $file_contents ;

以上就是php中,比較常用的6中遠(yuǎn)程請求方法,希望對php新人的學(xué)習(xí)、工作有一定的幫助。當(dāng)然遠(yuǎn)程請求的方法肯定不止題主上面為大家介紹的這6中,如果你還有更好的方法,歡迎補充分享。軟件開發(fā)的學(xué)習(xí),就是一個分享式的學(xué)習(xí),讓我們一起在分享學(xué)習(xí)中,共進步。

php 怎么POST獲取數(shù)據(jù)?

方法1、最常見的方法是:$_POST['fieldname'];

說明:只能接收Content-Type:

application/x-www-form-urlencoded提交的數(shù)據(jù)

解釋:也就是表單POST過來的數(shù)據(jù)

方法2、file_get_contents("php://input");

說明:

允許讀取

POST

原始數(shù)據(jù)

$HTTP_RAW_POST_DATA

比起來,它給內(nèi)存帶來的壓力較小,并且不需要任何特殊的

php.ini

設(shè)置。

php://input

不能用于

enctype="multipart/form-data"。

解釋:

對于未指定

Content-Type

的POST數(shù)據(jù),則可以使用file_get_contents(“php://input”);來獲取原始數(shù)據(jù)。

事實上,用PHP接收POST的任何數(shù)據(jù)都可以使用本方法。而不用考慮Content-Type,包括

二進制文件

流也可以。

所以用方法二是最保險的方法

方法3、$GLOBALS['HTTP_RAW_POST_DATA'];

說明:

總是產(chǎn)生

$HTTP_RAW_POST_DATA

變量包含有原始的

POST

數(shù)據(jù)。

此變量僅在碰到未識別

MIME

類型的數(shù)據(jù)時產(chǎn)生。

$HTTP_RAW_POST_DATA

對于

enctype="multipart/form-data"

表單數(shù)據(jù)不可用

如果post過來的數(shù)據(jù)不是PHP能夠識別的,可以用

$GLOBALS['HTTP_RAW_POST_DATA']來接收,

比如

text/xml

或者

soap

等等

解釋:

$GLOBALS['HTTP_RAW_POST_DATA']存放的是POST過來的原始數(shù)據(jù)。

$_POST或

$_REQUEST

存放的是

PHP以key=value的形式格式化以后的數(shù)據(jù)。

但$GLOBALS['HTTP_RAW_POST_DATA']中是否保存POST過來的數(shù)據(jù)取決于centent-Type的設(shè)置,即POST數(shù)據(jù)時

必須顯式示指明Content-Type:

application/x-www-form-urlencoded,POST的數(shù)據(jù)才會存放到

$GLOBALS['HTTP_RAW_POST_DATA']中

當(dāng)前題目:php請求數(shù)據(jù)的方式,php請求數(shù)據(jù)的方式有哪些
網(wǎng)站地址:http://chinadenli.net/article48/hchdhp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計定制開發(fā)網(wǎng)站內(nèi)鏈Google外貿(mào)網(wǎng)站建設(shè)網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)