我正在尝试使用PHP来使用JSON。
我试着用卷发得到回应:
curl 'http://104.239.130.176:3000/api/users/authenticate?email=my_username_here&password=my_password'这在终点站没有给我任何回应。
我也试过用电子邮件换用户名:
curl 'http://104.239.130.176:3000/api/users/authenticate?username=my_username_here&password=my_password'我在PHP文件中编写了以下内容,但这给了我浏览器中的404错误。
<?php
// Parameters
$tpm_base_url = 'http://104.239.176.130:3000/'; // ending with /
$req_uri = 'api/users/authenticate'; // GET /passwords.json
$username = 'my_username';
$password = 'my_password';
// Request headers
$headers = array(
'Content-Type: application/json; charset=utf-8'
);
// Request
$ch = curl_init($tpm_base_url . $req_uri);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, TRUE); // Includes the header in the output
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password); // HTTP Basic Authentication
$result = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// Get headers and body
list($headers, $body) = explode("\r\n\r\n", $result, 2);
$arr_headers = explode("\r\n", $headers);
$arr_body = json_decode($body, TRUE);
// Show status and array of passwords
echo 'Status: ' . $status . '<br/>';
print_r($arr_body);我不知道我在这里哪里出了问题。API开发人员的说明如下:
API有一个基本的JWT安全性,所以第一个请求令牌。
将请求发送到:http://104.239.176.130:3000/api/users/authenticate
发布于 2016-09-21 06:22:34
curl -H "Accept: application/json" -H "Content-Type: application/json" --data "username=my_username_here&password=my_password" http://104.239.176.130:3000/api/users/authenticate在终端上试试这个,看看你有没有回复。
在php中,使用CURLOPT_POSTFIELDS代替CURLOPT_USERPWD发送用户/pass
发布于 2016-09-21 06:35:33
尝尝这个
$ch = curl_init($tpm_base_url . $req_uri);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, TRUE); // Includes the header in the output
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
"email=$username&password=$password");
$result = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);https://stackoverflow.com/questions/39608589
复制相似问题