您好我正在尝试使用 curl 在 jsp 页面上发布 Http 帖子。但它不起作用。这是我正在尝试的 php 代码。
<?php
if(isset($_POST['submit'])){
$captcha = $_POST['answer'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://example.com/post_comments.jsp");
curl_setopt($ch, CURLOPT_REFERER, 'http://www.example.com');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
"post_id=123&body=blabla&title=blabla&name=blablabla8&captcha=$captcha");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result= curl_exec ($ch);
curl_close ($ch);
echo $result;
}else {
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<img src="http://example.com/captcha.jsp" /> <input name="answer" />
<p><input type="submit" name="submit" value="submit"></p>
</form>
<?php
}
?>
请任何人指导纠正它。提前致谢