Last active
December 18, 2015 19:59
-
-
Save kobake/5836879 to your computer and use it in GitHub Desktop.
Qiita API を使うときには User-Agent を設定しないと 500 Internal Server Error が発生する ref: http://qiita.com/kobake@github/items/d256fd1665284fd3c65a
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ php QiitaApiSimple.php | |
Warning: file_get_contents(https://qiita.com/api/v1/items): failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error | |
in QiitaApiSimple.php on line 3 | |
Call Stack: | |
0.0000 338728 1. {main}() QiitaApiSimple.php:0 | |
0.0000 338880 2. file_get_contents() QiitaApiSimple.php:3 | |
PHP Warning: file_get_contents(https://qiita.com/api/v1/items): failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error | |
in QiitaApiSimple.php on line 3 | |
PHP Stack trace: | |
PHP 1. {main}() QiitaApiSimple.php:0 | |
PHP 2. file_get_contents() QiitaApiSimple.php:3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$url = 'https://qiita.com/api/v1/items'; | |
$opts = array( | |
'http'=>array( | |
'method'=> "GET", | |
'header'=> "User-Agent: OreOreAgent\r\n" | |
) | |
); | |
$context = stream_context_create($opts); | |
$response = file_get_contents($url, false, $context); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user_agent='OreOreAgent' (追記) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$url = 'https://qiita.com/api/v1/items'; | |
$opts = array( | |
'http'=>array( | |
'method'=> "GET", | |
'header'=> "User-Agent: OreOreAgent\r\n" | |
) | |
); | |
$context = stream_context_create($opts); | |
$response = file_get_contents($url, false, $context); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
ini_set('user_agent', 'OreOreAgent'); | |
$url = 'https://qiita.com/api/v1/items'; | |
$response = file_get_contents($url); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$url = 'https://qiita.com/api/v1/items'; | |
$response = file_get_contents($url); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment