POST RAW usando cURL en PHP
¿Cómo puedo hacer un POST RAW en PHP usando cURL?
Raw post como en sin ninguna codificación, y mis datos se almacenan en una cadena. Los datos deben formatearse así:
... usual HTTP header ...
Content-Length: 1039
Content-Type: text/plain
89c5fdataasdhf kajshfd akjshfksa hfdkjsa falkjshfsa
ajshd fkjsahfd lkjsahflksahfdlkashfhsadkjfsalhfd
ajshdfhsafiahfiuwhflsf this is just data from a string
more data kjahfdhsakjfhsalkjfdhalksfd
Una opción es escribir manualmente todo el encabezado HTTP que se envía, pero eso parece menos óptimo.
De todos modos, ¿puedo simplemente pasar opciones a curl_setopt() que dicen usar POST, usar text/plain, y enviar los datos sin procesar desde un $variable
?
101
Author: Peter Mortensen, 2009-05-16
1 answers
Acabo de encontrar la solución, respondiendo a mi propia pregunta en caso de que alguien más se tropiece con ella.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://url/url/url" );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, "body goes here" );
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/plain'));
$result=curl_exec ($ch);
186
Author: The Unknown,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-05-16 01:36:41
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-05-16 01:36:41