400 Bad Request,工作正常localhost

时间:2016-08-20 18:19:26

标签: php curl

我试图通过php curl获取一些信息。它在我的localhost wamp环境中工作得非常好,但是当我在服务器上在线上传它时,它说: -

400 Bad Request

nginx/1.9.12

这是我的代码: -

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://api.blockcypher.com/v1/eth/main/addrs?token=some_token") 
curl_setopt($ch, CURLOPT_POST, 1);

// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec ($ch);
curl_close ($ch);
var_dump($server_output);

1 个答案:

答案 0 :(得分:0)

在API文档中,我没有看到任何令牌放入查询POST请求的地方。

所以,我已经检查过您的代码,但是将令牌作为帖子字段并且有效:

<?php

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://api.blockcypher.com/v1/eth/main/addrs");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'token=some-token-here');

// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec ($ch);
curl_close ($ch);
var_dump($server_output);

docs:https://dev.blockcypher.com/?javascript#generate-address-endpoint

相关问题