不是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);