我试图构建一个使用simplenote的应用程序,但是我在认证部分遇到了问题。我得到了一个400错误(糟糕的请求)。我猜想这个问题与simplenote无关,而是我对文档的理解。
下面是api的意思:
HTTP到以下网址:https://simple-note.appspot.com/api/login 请求正文应该包含以下内容,但base64 64编码:email=电子邮件地址和密码=密码。 为了清楚起见,您将将email=与用户的电子邮件地址(修整)、&password=和用户密码连接起来;然后将得到的字符串作为HTTP正文发送。(不要使用用于POSTed web窗体的标准变量编码对此请求进行编码。我们基本上忽略了这个请求的Content+Type头,但是文本/纯文本在这里最有意义。)
到目前为止,我的代码如下:
$url = 'https://simple-note.appspot.com/api/login';
$data = array('email' => base64_encode($email), 'password' => base64_encode($password));
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data),
),
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
var_dump($result);发布于 2014-01-17 12:48:35
我想他们的意思是:
$data = base64_encode(http_build_query(array(
"email" => $email,
"password" => $password
));因此,base64编码产生的字符串,而不是各个部分。
至于提出要求。我可以推荐您看一下cURL,它比file_get_contents快得多。
https://stackoverflow.com/questions/21186281
复制相似问题