php 获取请求主体,可以使用PHP中的cURL将数据添加到HTTP请求的主体中吗?

不是100%肯定你的意思……

如果你想抓取一个页面,并替换内容/插入一些内容 – 你可以这样做:

$ch = curl_init("https://stackoverflow.com/questions/1361169/possible-to-add-data-to-the-body-of-a-http-request-using-curl-in-php");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);

$output = curl_exec($ch);

$output = str_replace('Possible to add data to the body of a HTTP request using cURL in PHP?', 'I have just changed the title of your post...', $output);

echo $output;

这将打印此页面…

编辑:

添加新信息后,我认为您应该可以使用POSTFIELDS ..只需记住将POST设置为1 ..

例如. (像这样 – 未经测试)

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://stackoverflow.com");

curl_setopt($ch, CURLOPT_USERAGENT, "My user agent");

curl_setopt($ch, CURLOPT_HTTPHEADER, $myOtherHeaderStringVariable);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_HEADER, 1);

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, "I want to add data to the request here");

$output = curl_exec($ch);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值