简体   繁体   English

PHP curl不起作用,如果我将字符串作为url传递,而不是如果我从db中获取URL而不是curl则返回错误

[英]PHP curl not working, if i pass string as url than its working if i fetch url from db than curl returning error

working code 工作代码

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://###.#####.###/####/####/T0103/templateCustomWebPage.do?webId=1209221452326&editCurrentLanguage=1209221452328&customWebPageId=1292822288140001019");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$data = curl_exec($ch);
curl_close($ch);
echo $data;[/code]

but if i use url from database than its not working. 但是,如果我使用数据库中的url而不起作用。

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $r->url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$data = curl_exec($ch);
curl_close($ch);
echo $data;

following error will be display... 将显示以下错误...

parameter is wrong ,please check your input url.
Your input URL:
http://###.#####.###/####/####/T0103/templateCustomWebPage.do?webId=1209221452326&editCurrentLanguage=1209221452328&customWebPageId=1292822288140001019

Thank you in advance! 先感谢您!

Your url is stored with html entities in the database. 您的网址与html实体一起存储在数据库中。 The CURL call doesn't accept those. CURL调用不接受这些。

Try this: 尝试这个:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, html_entity_decode($r->url));
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$data = curl_exec($ch);
curl_close($ch);
echo $data;

I've added html_entity_decode http://php.net/manual/en/function.html-entity-decode.php 我添加了html_entity_decode http://php.net/manual/en/function.html-entity-decode.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM