当我开发一个正在开发的应用程序时,我遇到了一个有趣的问题。希望有人知道为什么会发生这种情况/如何调整我的工作流程!可以通过浏览器查看URL,但不能通过CURL查看URL
背景:
我正在写一个应用程序,帮助大学的学生彼此联系。其基本工作流程如下:
- 为服务用户注册
- 该应用程序使用卷曲轮询大学目录的名称
- 存储在数据库表中的联系信息
我的测试网站是罗格斯大学目录(http://www.acs.rutgers.edu/directory) 我可以通过我的浏览器访问服务(帖子到http://www.acs.rutgers.edu/pls/pdb_p/Pdb_Display.search_results),但如果我尝试通过CURL发布相同的信息,则会出现404错误。
注意:如果我直接从浏览器打开该URL并且不使用它们的表单提交数据,我会得到相同的错误。
代码:
这里是他们的目录网站使用的代码:
<fieldset>
<legend>Search For People</legend>
<div style="width:50%;margin-left:auto;margin-right:auto;">
<form method="post" action="http://www.acs.rutgers.edu/pls/pdb_p/Pdb_Display.search_results" name="thisform" onkeyup="highlight()" onclick="highlight()">
<p>
<label for="p_name_last">Last Name: [Required]</label><br>
<input tabindex="1" accesskey="L" class="required" type="text" id="p_name_last" name="p_name_last" size="25" maxlength="23">
</p>
<p>
<label for="p_name_first">First Name: [or initial]</label><br>
<input tabindex="2" accesskey="f" type="text" id="p_name_first" name="p_name_first" size="25" maxlength="23">
</p>
<input tabindex="3" type="submit" value="Search">
</form>
</div>
这里是我使用卷曲的服务代码:
<?php
$p_name_last = "doe";
$p_name_first = "";
$curlPost = 'p_name_last=' . urlencode($p_name_last) . '&p_name_first=' . urlencode($p_name_first) . '&SUBMIT=Search';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.acs.rutgers.edu/pls/pdb_p/Pdb_Display.search_results');
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
if(! $result = curl_exec($ch))
{
trigger_error(curl_error($ch));
}
curl_close($ch);
echo "<pre>";
print_r($result);
?>
任何想法或建议将不胜感激!
谢谢,
迈克
你是个天才。谢谢 – Swift 2010-08-23 20:58:21