2017-01-15 15 views
0

私はこのようなURLが、& text=http://example2.com/song.mp3どのように& URLに&

私はそれがエラーの下に表示さfile_get_contents()を使用して、URLのデータを取得しようhttps://www.example.com/send?id=1

PHPの警告:のfile_get_contents(https://www.example.com/send?id=1 &アンプtext=http://example2.com/song.mp3): 失敗しました。ストリームを開く:HTTP要求に失敗しました! HTTP/1.1 501未実装

および&は& ampに変換されています。そのため、URLは機能していません。

htmlspecialchars_decode()preg_replace()を&に送信しましたが、何もしませんでした。

これを解決するにはどうすればよいですか?

+0

@ Xorifelseは%26でエスケープしていませんでした – theModerator713

+0

URLを参照するのはhttpまたはhttpsですか? – msk

+0

@msk https、... – theModerator713

答えて

1

私はそれだけでHTTPが

<?php 
    $cSession = curl_init(); 
    curl_setopt($cSession,CURLOPT_URL,"https://www.example.com/send?id=1&text=http://example2.com/song.mp3"); 
    curl_setopt($cSession,CURLOPT_RETURNTRANSFER,true); 
    curl_setopt($cSession,CURLOPT_HEADER, false); 
    $result=curl_exec($cSession); 
    curl_close($cSession); 
    echo $result; 
?> 

参照してくださいを要求作るあなたはfile_get_contents()を使用している場合、参照サーバは、そのサーバ内allow_url_fopenを有効にする必要がありますが、cURLのライブラリですので、あなたがより良い、cURL代わりのfile_get_contents()を使用することを考えます以下のリンク

file_get_contents script works with some websites but not others

cURL vs file_get_contents

+0

URLの前後に '&'の前後にスペースがあるようです。スペースを削除しようとすることができます –

関連する問題