0
我正在使用CURL调用API。该调用返回一个HTML DOM树,我在iframe中回显。问题是,基地网址是指我自己的网站,而不是API的网站。例如:<script type="text/javascript" src="/swf/swfobject.js"></script>
将引用我的网站而不是API的。我已经看过CURL设置选项,但是我找不到我在找什么,有人可以帮我吗?我尝试使用preg_replace工作,但我有很多不同的不可预知的链接。 (和它的方式肮脏的!)iframe中的PHP CURL更改基础url?
代码卷曲呼叫:
function CallAPI($method, $url, $data = false)
{
$curl = curl_init();
switch ($method)
{
case "POST":
curl_setopt($curl, CURLOPT_POST, 1);
if ($data)
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
break;
case "PUT":
curl_setopt($curl, CURLOPT_PUT, 1);
break;
default:
if ($data)
$url = sprintf("%s?%s", $url, http_build_query($data));
}
// Optional Authentication:
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
//curl_setopt($curl, CURLOPT_USERPWD, "username:password");
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
return curl_exec($curl);
}
$output = CallAPI($method, $url, $data);
echo $output;
HTML:
<iframe src="videorecorder.php" frameBorder="0" scrolling="no"></iframe>
请帮帮我!
感谢
谢谢,但它不是为我工作。也许我做错了什么。我把这一行放在switch语句之后:'curl_setopt($ curl,CURLOPT_REFERER,“http://www.google.com”);'我仍然遇到这个错误'GET http://www.mywebsite.com/swf/ history/history.js 404(Not Found)'而不是google.com。 – user1081577 2013-04-24 11:27:16
你的问题并没有指出你到底在做什么。 – 2013-04-24 11:31:31
我正在调用一个API,它返回一个HTML页面,我把它放在页面上的iframe中。在他们的服务器上,某些CSS/JS文件的链接是这样引用的:'src =“/ swf/swfobject.js'在我的iframe中使用的基础href是我网站的基础href,但是文件arn'在我的网站上,他们是在他们的!所以基础href应该是一样的API。那么我如何使用或改变它到正确的基础href? – user1081577 2013-04-24 12:08:19