Table of Contents
文档版本
Implementation Scope:
现象
环境信息
发起HTTP POST请求方·系统环境
正确接收POST请求的PHP for MS Windows·系统环境
无法接收POST请求的PHP for Linux·系统环境
更多信息
解决步骤
总结:
Disclaimers:
Home php教程 php手册 不同操作系统下PHP接收HTTP POST数据问题

不同操作系统下PHP接收HTTP POST数据问题

Jun 21, 2016 am 09:09 AM
data http nbsp php post

数据|问题

文档版本

版本创建时间创建人备注1.0.0606.12003-6-6郑           昀第一稿    

Implementation Scope:

本文档将说明PHP页面接收HTTP组件POST的数据问题。一般来说,POST过来的二进制数据流,只需要PHP用$HTTP_RAW_POST_DATA就可以接收。但是,我们遇到的情况却不是这样。 继续阅读之前,我们假设您熟悉以下知识:n         PHPn         MSXML2.ServerXMLHTTPn         HTTP POST 

现象

我们遇到了这么一个问题:我从Windows 2000上,利用MSXML2.ServerXMLHTTP接口向Linux Apche下的PHP页面POST二进制数据流。PHP页面的$HTTP_RAW_POST_DATA变量为空,得不到数据,而且sizeof($_POST)的值也是0。 但是,如果我同样向一个Windows 2000 IIS下的PHP页面POST数据,却可以用$HTTP_RAW_POST_DATA接收到正常数据。为什么二者有这种区别呢?

环境信息

发起HTTP POST请求方·系统环境

Windows XP Professional(Service Pack 1)MSXML3.Dll(SP3 / 版本号:8.30.9926.0)调用ServerXMLHTTP的代码是:       MSXML2::IServerXMLHTTPRequestPtr pIXMLHttpRequest = NULL;              HRESULT hr = pIXMLHttpRequest.CreateInstance("MSXML2.ServerXMLHTTP");        hr = pIXMLHttpRequest->open(L"POST",                                                                bstrPHPURL,                                                                VARIANT_FALSE,  // 同步发送                                                               vtMissing,                                                                vtMissing);        hr = pIXMLHttpRequest->send(varData); 

正确接收POST请求的PHP for MS Windows·系统环境

用$HTTP_RAW_POST_DATA正常接收了数据的PHP for Windows安装信息:PHP Version 4.2.2SystemWindows NT 5.1 build 2600Server APICGI关于使用这个全局变量的相关设置:DirectiveLocal ValueMaster Valuealways_populate_raw_post_data00 

无法接收POST请求的PHP for Linux·系统环境

无法用$HTTP_RAW_POST_DATA接收POST数据的PHP for Linux安装信息:PHP Version 4.3.2RC3System Linux atm2 2.4.18-1 #1 Wed May 29 10:45:23 CST 2002 i686 Server API Apache Registered PHP Streams php, http, ftp 关于使用这个全局变量的相关设置:DirectiveLocal ValueMaster Valuealways_populate_raw_post_dataOnOn  

更多信息

照理说,只要php.ini中定义了; Always populate the $HTTP_RAW_POST_DATA variable.always_populate_raw_post_data = On就完全可以用$HTTP_RAW_POST_DATA变量来接收数据。起码$_POST变量是可以测算出POST到页面的数据大小的。 我确实看到有几个人试图报告“Empty $HTTP_RAW_POST_DATA”是一个PHP的Bug,但是PHP维护人员说肯定不是。

解决步骤

不知道Windows下的PHP 4.2.2怎么一直可以接收。但是如果我显式声明Content-Type为file的话,Linux下的PHP 4.3.2RC3就可以正常接收POST数据了。设置头信息的代码如下:hr = pIXMLHttpRequest->setRequestHeader(                                                               _bstr_t("Content-Type"),                                                                _bstr_t("file")); 这样做的话,PHP 4.2.2 for Windows和PHP 4.3.2RC3 for Linux都可以用$HTTP_RAW_POST_DATA接收,没有问题。 

总结:

如果你的$HTTP_RAW_POST_DATA不在那儿了,你可以在调用HTTP组件发送HTTP POST请求时,指定Content-Type为file。 

Disclaimers:

本文档所包含的信息代表了在发布之日,zhengyun对所讨论问题的当前看法。本文档不应理解为zhengyun一方的承诺,zhengyun不保证所给信息在发布之日以后的准确性。 本文档仅供参考。用户必须遵守所有适用的版权法。在不对版权法所规定的权利加以限制的情况下,如未得到 zhengyun和CSDN.Net明确的书面许可,不得出于任何目的、以任何形式或手段(电子的、机械的、影印、录制等等)复制、传播本文的任何部分,也不得将其存储或引入到检索系统中。



Statement of this Website
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

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

7 PHP Functions I Regret I Didn't Know Before 7 PHP Functions I Regret I Didn't Know Before Nov 13, 2024 am 09:42 AM

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

See all articles