日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > php >内容正文

php

http协议与php关系,PHP中的HTTP协议

發(fā)布時(shí)間:2023/12/19 php 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 http协议与php关系,PHP中的HTTP协议 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

無(wú)狀態(tài):每次請(qǐng)求完成就結(jié)束連接,下一次請(qǐng)求與上次請(qǐng)求沒(méi)有關(guān)系。

報(bào)文:HTTP交互的信息。

telnet模擬請(qǐng)求: // GET方式,最后回車(chē)換行

Aston$ telnet 127.0.0.1 80

GET /Tools/Test/http.php HTTP/1.1

Host:localhost

// POST方式,最后回車(chē)換行,輸入?yún)?shù)

Aston$ telnet 127.0.0.1 80

POST /Tools/Test/http.php HTTP/1.1

Host:localhost

Content-type:application/x-www-form-urlencoded

Content-length:20

name=chenjian&age=28

fiddler用法:

利用file_get_content來(lái)發(fā)送數(shù)據(jù): $data = array(

'name' => 'chenjian',

'age' => 28

);

$postData = http_build_query($data);

$opts = array(

'http' => array(

'host' => "localhost\r\n",

'method' => "POST",

'header' => "Content-type:application/x-www-form-urlencoded\r\n" . "Content-length:".strlen($postData)."\r\n",

'content' => $postData

);

);

$context = stream_context_create($opts);

file_get_contents("http://localhost/http/index.php", false, $context);

socket方式: $data = array(

'name' => 'chenjian',

'age' => 28

);

$postData = http_build_query($data);

$fp = fsockopen("localhost", 80, $errno, $errorStr, 5);

$request = "POST http://localhost/http/socket.php HTTP/1.1\r\n";

$request .= "Host:locahost\r\n";

$request .= "Content-type:application/x-www-form-urlencoded\r\n";

$request .= "Content-length:" . strlen($postData) . "\r\n";

$request .= $postData;

fwrite($fp, $request);

while (!feof($fp)) {

echo fgets($fp, 1024);

}

fclose($fp);

curl拓展: $url = "http://localhost/http/curl.php";

$data = array(

'name' => 'chenjian',

'age' => 28

);

// 1. 初始化curl會(huì)話

$ch = curl_init();

// 2. 設(shè)置

curl_setopt($ch, CURLOPT_URL, $url); //提交網(wǎng)址

curl_setopt($ch, CURLOPT_POST, 1); //提交方式

curl_setopt($ch, CURLOPT_POSTFIELDS, $data); //提交數(shù)據(jù)

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //提交成功后返回?cái)?shù)據(jù)字符串

// 3. 執(zhí)行

$out_put = curl_exec($ch);

// 4. 關(guān)閉會(huì)話

curl_close($ch);

var_dump($out_put);

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)

總結(jié)

以上是生活随笔為你收集整理的http协议与php关系,PHP中的HTTP协议的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。