如何使用cURL发送原始POST数据? (PHP) [英] How to send raw POST data with cURL? (PHP)

查看:260
本文介绍了如何使用cURL发送原始POST数据? (PHP)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 $ HTTP_RAW_POST_DATA 将原始POST数据发送到网页,但我的尝试失败,并提供了未定义的索引通知。

I'm attempting to send raw POST data to a page using $HTTP_RAW_POST_DATA, but my attempts failed and an undefined index notice was given.

我尝试过以下操作:

curl_setopt($handle, CURLOPT_POSTFIELDS, 'Raw POST data');   // Doesn't seem to work at all.
curl_setopt($handle, CURLOPT_POSTFIELDS, array('Raw POST data'));   // 0 => Raw POST data

我做了一些研究,有些人建议发送标题(

I did some research and some people had suggested sending a header (Content-Type: text/plain) in the request, which didn't seem to affect anything.

如果任何人都能够访问您的帐户,提供这个问题的解决方案,我会非常感谢。谢谢!

If anyone is able to provide a solution for this issue I would greatly appreciate it. Thank you!

推荐答案

由于一些奇怪的原因,上述标题似乎修复它,以前它不工作,不确定为什么它现在工作。无论如何,对于那些不知道这是代码:

For some odd reason the aforementioned header thing seems to fix it, previously it wasn't working, I'm unsure why it works now. Anyway, for those who don't know this is the code:

curl_setopt($handle, CURLOPT_HTTPHEADER, array('Content-Type: text/plain'));

这篇关于如何使用cURL发送原始POST数据? (PHP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆