卷曲方法 GET 不起作用
我一直在尝试让curl 从表单发送GET 方法。我已经构建了将所有表单数据连接在一起的 URL。如果我直接在地址栏中输入 get 请求,它可以工作,但不能与curl一起工作。如果我回显 $data,我实际上会收到一条错误,指出“未找到对象!”我尝试显示curl_error()内容,但它返回空。非常感谢大家的帮助。
这就是我到目前为止所得到的:
$url = complete url of get request that works when directly placed into adress bar
curl_setopt($ch, CURLOPT_URL, $url);
$data = curl_exec ($ch);
curl_close ($ch);
echo $data;
谢谢大家帮助我。我尝试了下面的代码,它确实说“成功”。当我回显 $data 时,我瞬间看到“成功”,然后我得到“未找到对象!”错误。
$url = complete url of get request that works when directly placed into adress bar
$ch = curl_init($url);
if ($ch) {
echo "Success";
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec ($ch);
curl_close ($ch);
}
else {
echo "Could not initialize curl session";
}
我可能会收到错误,因为我将 GET 转发到的链接会将其转发到另一个链接来处理数据。
I have been trying to get curl to send a GET method from a form. I have constructed the URL with all the form data concatenated. If I type in the get request directly into the address bar it works but will not work with the curl. If i echo the $data I will actually receive an error stating "Object not found!" I tried displaying curl_error() contents and it return empty. Thank you very much everyone for your help.
This is what i have so far:
$url = complete url of get request that works when directly placed into adress bar
curl_setopt($ch, CURLOPT_URL, $url);
$data = curl_exec ($ch);
curl_close ($ch);
echo $data;
Thank you for helping me everyone. I tried the following code and it does say "sucess". When I echo $data, I see a "sucess" for a split second and then I get the "Object not found!" error.
$url = complete url of get request that works when directly placed into adress bar
$ch = curl_init($url);
if ($ch) {
echo "Success";
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec ($ch);
curl_close ($ch);
}
else {
echo "Could not initialize curl session";
}
I may be getting errors because the the link I forward the GET to will forward it to another link to process the data.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
尝试添加
这应该强制它以字符串形式返回数据而不是输出它。
有关更多详细信息,请参阅文档。
Try adding the
This should force it to return the data as a string instead of outputting it.
See the documentation for more details.
尝试使用 CURLOPT_RETURNTRANSFER 选项:
Try using the CURLOPT_RETURNTRANSFER option:
我相信您缺少一个用于初始化会话的curl_init。
使用建议的代码进行编辑
尝试复制并粘贴以下代码:
并让我们知道curl 会话是否已成功初始化。
I believe you are missing a curl_init to initialize the session.
Edit with suggested code
Try copying and pasting the below code:
And let us know if the curl session is initialized successfully.
我遇到了同样的问题并解决如下:
遵循从发布到获取重置的正确顺序非常重要。即首先将 postfields 设置为 null,然后将 post 设置为 0,然后将 httpget 设置为 true。一旦你设置了这个,那么你就可以放心,服务器将开始准备下一个请求,就像 get 请求一样,否则不会。此后,设置选项的其余部分和 url(以及所有参数)。这将确保正确发出并执行获取请求。
希望这有帮助...
I faced the same issue and resolved it as follows:
It is important that you follow the correct order for reset from post to get. ie first set the postfields to null, then post to 0 and then httpget to true. once you have set this then you can be assured that the server will start preparing the next request like a get request else not. Thereafter, set the rest of the option and the url(along with all the parameters). This will ensure the get request is properly made and executed.
Hope this helps...
请尝试 http_build_query() 函数来创建查询字符串我认为这会有所帮助,它在我的情况下有效
Please try http_build_query() function for create query string i think this will help , it is work in my case