2014-10-27 74 views
0

我想打电话给在纯PHP的API,但是当我使用的file_get_contents,卷曲,get_header,我有我的Web服务器everithing启用检查。(OpenSSL的,延长= php_openssl.dll)HTML的API调用状态405

我想知道为什么这不运行?

使用的file_get_contents

<?php 
    $username = '[email protected]'; 
    $password = 'newnew'; 
    $medium = 'WEB'; 
    $json = file_get_contents("http://new.ezeeinfosolutions.com/busservices/auth/getAuthToken?namespaceCode=demo&[email protected]&password=newnew&devicemedium=WEB"); 
    $array = json_decode($json, true); 
    echo $array; 
    echo $array['status']; // status 
    echo $array['datetime']; // date time 
    echo $array['data']['authToken']; // auth token 
    echo $array['data']['role']['code']; // code 
?> 

输出: 的file_get_contents(http://new.ezeeinfosolutions.com/busservices/auth/getAuthToken?namespaceCode=demo&username=ram%40demo.com&password=newnew&devicemedium=WEB):未能打开流:HTTP请求失败! HTTP/1.1 405方法不使用crul在/home/vkacadem/public_html/api/index.php允许第5行

$ch = curl_init("http://new.ezeeinfosolutions.com/busservices/auth/getAuthToken?namespaceCode=demo&username=$username&password=$password&devicemedium=$medium"); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_HEADER, 0); 
$data = curl_exec($ch); 
curl_close($ch); 
echo $data; 
**0/p: no response?** 

我的API是通过GET方法等待呼叫。

+0

您正在使用HTTP。你为什么要检查openssl? – 2014-10-27 10:10:37

+0

如果不介意,你可以告诉我你什么时候使用openssl只是为了这个任务,我搜索了谷歌的一切。我总是保证stackteam – 2014-10-27 10:38:01

回答

0

您需要发布数据。在发送请求之前添加

curl_setopt($ch, CURLOPT_POST); 

建议:如果您使用的是Chrome,请安装邮递员扩展程序。将允许您轻松调试此类问题。

+0

[**快速链接邮递员**](http://getpostman.com/) – 2014-10-27 10:34:06

+0

非常感谢我得到了这个{“status”:1,“datetime”:“2014-10- 27 16:00:24“,”data“:{”authToken“:”11656053df210024257eed0ee8373e00e41c025a“,”role“:{”code“:”USER“,”name“:”User“,”activeFlag“:1}}}在这之后,我想包括显示我的数据json_decode?接下来我要做什么来显示数据 – 2014-10-27 10:35:45

+0

json_decode将返回一个可迭代的对象,因此您可以使用foreach的print_r来迭代它,或者只是打印出您感兴趣的信息。请参见http:// php。 net/manual/en/function.json-decode.php了解更多详情。不要忘记接受答案;) – motanelu 2014-10-27 10:38:23

0

这些都是你的头API(http://new.ezeeinfosolutions.com/busservices/auth/getAuthToken?namespaceCode=demo&username=ram%40demo.com&password=newnew&devicemedium=WEB)返回: Response Headers Allow:POST Connection:keep-alive Content-Length:0 Date:Mon, 27 Oct 2014 10:33:02 GMT Server:nginx/1.4.4

这种资源只允许POST方法,所以你需要使用POST的这一请求。

+0

非常感谢您的宝贵答案,如果我理解正确意味着我需要更改表单操作

method =”get“发布 – 2014-10-27 10:50:42

相关问题