发布带有cURL的textarea表单 [英] Posting a textarea form with cURL
本文介绍了发布带有cURL的textarea表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何发布textarea表单?
How would I go about posting a textarea form?
<form method="post" action="/user/test/shoutbox/add" id="shoutPost" class="clearit">
<input name="formtoken" type="hidden" value="852f8fde54190fa5f9aa47172d492f829c1b"/>
<input type="hidden" name="backto" value="/user/test/shoutbox" />
<textarea id="shoutmsg" name="message"></textarea>
<input type="submit" name="submit" class="confirmButton" value="Post" id="sbPost" />
这应该能正常工作吗?
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_POST, 1);
$postfields .= "&message=".$msg;
$postfields .= "&submit=sbPost";
curl_setopt($ch, CURLOPT_POSTFIELDS,$postfields);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
$page = curl_exec($ch);
但不是因为某种原因发布...
but it's not posting for some reason...
推荐答案
curl_setopt($ch, CURLOPT_REFERER,"URLHERE");
curl_setopt($ch, CURLOPT_URL,"URLHERE");
curl_setopt($ch, CURLOPT_POST, 0);
$page = curl_exec($ch);
$formtoken = explode('name="formtoken" type="hidden" value="',$page);
$formtoken = explode('"/> ',$formtoken[1]);
$formtoken = $formtoken[0];
$backto = explode('type="hidden" name="backto" value="',$page);
$backto = explode('" />',$backto[1]);
$backto = $backto[0];
curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/cookiejar-$randnum");
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_URL,"URLHERE");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_POST, 1);
$postfields = "formtoken=".$formtoken;
$postfields .= "&backto=".$backto;
$postfields .= "&message=".$msg;
$postfields .= "&submit=Post";
curl_setopt($ch, CURLOPT_POSTFIELDS,$postfields);
$page = curl_exec($ch);
这篇关于发布带有cURL的textarea表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文