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

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 ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

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

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

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

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

See all articles