search
HomeBackend DevelopmentPHP TutorialPHP中Http协议post请求参数_php实例

本文给大家介绍PHP中Http协议post请求参数,具体内容如下所示:

WEB开发中信息基本全是在POST与GET请求与响应中进行,GET因其基于URL的直观,易被我们了解,可POST请求因其信息的隐蔽,在安全的同时,也给开发者们模拟发送带来了麻烦。接下来的几篇博文中,我将结合自己的笔记和理解,详细解释PHP进行POST请求的几种方法,如有错误,烦请指正。

  HTTP协议信息是WEB开发中的一项重要内容,了解它可以帮助我们更深刻地理解BS交互,也有利于我们从更底层理解WEB开发。HTTP协议是一种简单灵活方便的通讯协议,并且要记住,它是一种无状态的协议,即它是一种无记忆的协议,每一次的交互都是单独的。

  我们可以用浏览器的开发工具(IE的F12  火狐的FireBug等)的“网络”面板来查看HTTP头信息。

  一般地HTTP头信息分为三类:请求信息,响应信息和交互信息(个人认为也是请求信息的一种)。

1,请求信息:

  在访问一个网站时会由客户端发出请求信息,此信息不带有数据,只是单纯地向服务器接触,促使服务器返回响应信息。

  其格式为两部分:请求行和消息报头。

A.请求行: method(请求方法)  path(请求站内地址)   HTTP/version(协议/版本信息)

  常见的请求方法有GET/POST/HEAD/OPTION等

B.消息报头:

  Host(必须):主机和端口号,端口号默认为80

  Accept:期望接收内容类型(image/gif  text/html   */*)

  Accept-Encoding:期望接收的压缩类型(gzip deflat)

  Accept-Charset:期望接收的字符集(utf-8)

  Accept-Language(zh-CN)

  Cookie:用户的Cookie信息

  Connection:连接控制

  User-Agent:客户端信息

  ... ...

以下是一个典型的请求头信息:

GET  index.php  HTTP/1.1
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate, sdch
Accept-Language:zh-CN,zh;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Cookie:SOHUHOMETAB=visit:2; IPLOC=CN1407; SUV=1510312046259910
Host:www.sohu.com
If-Modified-Since:Sat, 31 Oct 2015 12:45:22 GMT
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.99 Safari/537.36

2,响应信息

  服务器返回数据

  响应信息分为三部分:状态行 消息报头 响应正文

A.状态行:HTTP/version(协议/版本信息)  状态码   状态文本(对状态码的文本描述)

  状态码共有5类:

    1XX:表示临时响应,需要请求者继续操作

    2XX:表示响应成功,服务器成功地响应了请求

    3XX:表示重定向,需要请求者进一步操作

    4XX:表示客户端错误,服务器无法正常响应

    5XX:表示服务器端错误,服务器无法正常响应

具体信息可参考:HTTP状态码详解

B.消息报头:

  Server:服务器信息

  Content-Encoding:数据压缩格式

  Content-Length:数据长度

  Content-Type:数据类型

  Cache-Control:缓存控制

  Connection:连接控制

  Date:日期信息

  Expires:返回数据的过期信息

  Last-Modified:返回最后的修改时间

  Set-Cookie:设置客户端的Cookie信息

  ... ...

C.响应正文

  即返回的页面数据,在页面以HTML文档形式表现出来。

以下是常见的响应消息

HTTP/1.1  200  OK

Cache-Control:no-cache
Connection:close
Content-Encoding:gzip
Content-Length:6947
Content-Type:text/html; charset=GBK
Date:Sat, 31 Oct 2015 13:30:11 GMT
Expires:-1
Pragma:no-cache
Proxy-Connection:keep-alive
Server:nginx/1.2.5
Set-Cookie:JSESSIONID=yiuug4yejhc1cdbzydoxlcpn;Path=/

3,交互信息

  是包含了请求数据的请求信息 常见于用户上传文件 注册等

  其分为三部分:请求行 消息报头 请求正文

A.与请求信息的请求行相同

B.在请求报头的基础上添加了有关请求正文的数据

  Content-Type:上传信息的内容类型

  Content-Length:上传信息的长度

  ... ...

C.请求正文:

  即请求的具体数据串(name=xxx&passwork=xxx),当然为了安全起见,有时会对POST信息加密编码。

以下是典型的请求消息:

GET  login.php  HTTP/1.1
Host:passport.sohu.com
Accept:text/html,application/xhtml+xml,application/xml
Accept-Encoding:gzip, deflate
Accept-Language:zh-CN,zh;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Content-Length:166
Content-Type:application/x-www-form-urlencoded
Referer:http://mail.sohu.com/
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.99 Safari/537.36
Form Data
domain=sohu.com&callback=passport20008375022711697966_cb1446298206568&appid=1113&userid=FDFFDF%40sohu.com&password=a3f4384c2bc44fa909ffd0ecc5fa8eb9&persistentcookie=0

 明白了浏览器都往服务器上发送了些什么,那用其他方法伪装成一个服务器也就不是难事了。

下一节我会介绍PHP和JS处理最基本URL的方式,解决GET请求部分的同时,也将模拟发送POST请求的准备做足。

如果您觉得本博文对您有帮助,您可以推荐或点赞,如果您有什么问题,也可以在下方留言,一块讨论,谢谢。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
11 Best PHP URL Shortener Scripts (Free and Premium)11 Best PHP URL Shortener Scripts (Free and Premium)Mar 03, 2025 am 10:49 AM

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Working with Flash Session Data in LaravelWorking with Flash Session Data in LaravelMar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

Build a React App With a Laravel Back End: Part 2, ReactBuild a React App With a Laravel Back End: Part 2, ReactMar 04, 2025 am 09:33 AM

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Simplified HTTP Response Mocking in Laravel TestsSimplified HTTP Response Mocking in Laravel TestsMar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

cURL in PHP: How to Use the PHP cURL Extension in REST APIscURL in PHP: How to Use the PHP cURL Extension in REST APIsMar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

12 Best PHP Chat Scripts on CodeCanyon12 Best PHP Chat Scripts on CodeCanyonMar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Announcement of 2025 PHP Situation SurveyAnnouncement of 2025 PHP Situation SurveyMar 03, 2025 pm 04:20 PM

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio

Notifications in LaravelNotifications in LaravelMar 04, 2025 am 09:22 AM

In this article, we're going to explore the notification system in the Laravel web framework. The notification system in Laravel allows you to send notifications to users over different channels. Today, we'll discuss how you can send notifications ov

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)