停止curl删除端口号
当我卷曲以下页面时,
<?php
$ch = curl_init();
curl_setopt ($ch, CURLOPT_PORT, "8081");
curl_setopt ($ch, CURLOPT_URL, "http://192.168.0.14:8081/comingEpisodes/" );
curl_setopt($ch, CURLOPT_USERPWD, "user:pass");
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$curl_response = curl_exec($ch);
curl_close($ch);
echo $curl_response;
?>
返回了页面,但图像没有返回。我找到了问题所在。 192.168.0.14 是我的本地主机。我正在从运行端口 8081 的应用程序调用页面。Curl 似乎删除了该端口并将 192.168.0.14 更改为 locahost,因此图像不再链接到正确的位置。如何确保端口保留以便图像保留。谢谢
编辑:我认为端口之后的 /comingEpisodes 也是问题的一部分。
When I curl the following
<?php
$ch = curl_init();
curl_setopt ($ch, CURLOPT_PORT, "8081");
curl_setopt ($ch, CURLOPT_URL, "http://192.168.0.14:8081/comingEpisodes/" );
curl_setopt($ch, CURLOPT_USERPWD, "user:pass");
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$curl_response = curl_exec($ch);
curl_close($ch);
echo $curl_response;
?>
The page is returned however the images aren't. I located the problem. 192.168.0.14 is my local host. I am calling a page from an app the runs off port 8081. Curl seems to drop the port and change 192.168.0.14 to locahost and therefore the images are no longer linked to the right place. How do I make sure that the port remains so the images remain. Thanks
EDIT: I think the /comingEpisodes after the port is also part of the problem..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除非您正在构建 100% 代理,否则您会将 cURL 拉取的内容转储到浏览器中。现在,结果来自 cURL 结果转储到的页面,而不是来自原始 cURL 请求。
基本上,如果您访问 http://localhost 并且上述代码位于
index.php
中,那么页面正在请求 :8081/comingEpisodes 内容并将其转储到原始 http://locahost上下文中>。浏览器现在基于 http://localhost 找到的所有内容,而不是像来自curl 请求一样。您可以在将文档输出到某个“proxy.php?retrieve=old_url”之前替换文档中的所有内容链接,然后让所有这些现在通过相同的 cURL 上下文进行调用,但这是网络代理。
非常简单的演示
Unless you're building a 100% proxy, you're dumping the contents of the cURL pull in to a browser. The results now refer from the page that the cURL results are dumped to, not from the originating cURL request.
Basically, if you visit http://localhost and the above code resides in the
index.php
, that page is requesting the :8081/comingEpisodes contents and dumping it within the context of the originating http://locahost. The browser is now basing all the found content from http://localhost and not as if it were from the curl request.You could replace all the content links within the document before it's output to some "proxy.php?retrieve=old_url" and then make all those now call through the same cURL context, but that's the basis of a web proxy.
VERY SIMPLE DEMO