在 PHP 中使用 cURL 的 RAW POST [英] RAW POST using cURL in PHP
本文介绍了在 PHP 中使用 cURL 的 RAW POST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用 cURL 在 PHP 中执行 RAW POST?
How can I do a RAW POST in PHP using cURL?
原始帖子没有任何编码,我的数据存储在一个字符串中.数据格式应如下所示:
Raw post as in without any encoding, and my data is stored in a string. The data should be formatted like this:
... 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
一种选择是手动编写正在发送的整个 HTTP 标头,但这似乎不太理想.
One option is to manually write the entire HTTP header being sent, but that seems less optimal.
无论如何,我是否可以将选项传递给 curl_setopt(),比如使用 POST、使用文本/纯文本并从 $variable
发送原始数据?
Anyway, can I just pass options to curl_setopt() that say use POST, use text/plain, and send the raw data from a $variable
?
推荐答案
我刚刚找到了解决方案,有点像回答我自己的问题,以防其他人偶然发现它.
I just found the solution, kind of answering to my own question in case anyone else stumbles upon it.
$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);
这篇关于在 PHP 中使用 cURL 的 RAW POST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文