【发布时间】:2017-09-25 14:13:54
【问题描述】:
$Link = 'http://somewebsite.com/api.php?message=someMessage&user_id=' . $UserID . '&password=' . $UserPW;
echo $Link;
echo "<br><br>";
$PageResponse = file_get_contents($Link);
出于隐私考虑,我无法发布工作示例,但这是我遇到的问题。
当我回显 $Link 时,它会返回:
http://somewebsite.com/api.php?message=someMessage&user_id=redacted&password=redacted
但是 file_get_contents 返回和错误如下所示:
Warning: file_get_contents(http://somewebsite.com/api.php?message=someMessage&user_id=redacted&password=redacted): failed to open stream: No connection could be made because the target machine actively refused it. in C:\wamp64\www\hello.php on line 14
如果您注意到,它会将“&”字符更改为&amp;,这会破坏 url。有没有简单的方法来解决这个问题?
【问题讨论】:
-
这不是错误,这是一个特性
-
在使用
file_get_contents之前,您是否尝试过html_entity_decodeurl 字符串?否则str_replace会有所帮助。 -
已尝试解码和替换。转换仍然存在
标签: php file-get-contents