2012-03-04 56 views
14

cuando hago un eco sencilla de $ HTTP_RAW_POST_DATA me sale el error:Undefined variable: HTTP_RAW_POST_DATA

Undefined variable: HTTP_RAW_POST_DATA 

leí en php.ini que necesito para eliminar la marca

always_populate_raw_post_data = On 

pero todavía recibo el error y reinicié Apache también. Im usando PHP 5.3.6

+0

¿Está utilizando algún HTTP_RAW_POST_DATA para cualquier servicio web? – Milap

+0

en este ejemplo, no, pero originalmente seguí esta página http://phpmaster.com/web-services-with-php-and-soap-1/ y obtuve el error, así que creé una sola página para investigar el error. –

Respuesta

24

Si necesita acceder al cuerpo de POST prima que realmente debería favorecer el uso de la corriente php://input sobre $HTTP_RAW_POST_DATA según el relevant manual entry:

php://input is a read-only stream that allows you to read raw data from the request body. In the case of POST requests, it is preferable to use php://input instead of $HTTP_RAW_POST_DATA as it does not depend on special php.ini directives. Moreover, for those cases where $HTTP_RAW_POST_DATA is not populated by default, it is a potentially less memory intensive alternative to activating always_populate_raw_post_data. php://input is not available with enctype="multipart/form-data".

Así, para acceder al cuerpo de POST utilizando php://input:

$post = file_get_contents('php://input'); 
+0

gracias, vi esto cuando estaba leyendo lo indefinido pero no pensé en usarlo. pero estaba equivocado, gracias! –

19

Si obtiene

Notice: Undefined variable: HTTP_RAW_POST_DATA

Por favor, abra el archivo de servidor de añadir encontrar

$server->service($HTTP_RAW_POST_DATA); 

y reemplazar con 2 líneas siguientes.

if (!isset($HTTP_RAW_POST_DATA)) $HTTP_RAW_POST_DATA =file_get_contents('php://input'); 
$server->service($HTTP_RAW_POST_DATA); 

Espero que esto ayude.

+0

gracias a un hombre tonto ... – San

+0

su bienvenida. Disfrutar .. @San – Milap

+0

Milap ¿Tiene alguna idea de cómo obtener la respuesta de un script php, como usé el servicio de jabón y funciona bien, busqué muchos artículos y me sugieren que implemente ajax, php es del lado del servidor y quería para obtener una respuesta de él para que pueda usarlo en mi formulario html ... – San