RAW POST使用PHP中的cURL [英] RAW POST using cURL in PHP
本文介绍了RAW POST使用PHP中的cURL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎样才能做一个RAW POST在PHP中使用卷曲?
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,使用纯文本/,并从 $变量发送的原始数据
?
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);
这篇关于RAW POST使用PHP中的cURL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文