【发布时间】:2017-02-17 09:06:25
【问题描述】:
我对这件事很陌生。我正在尝试创建一个搜索表单,它允许通过 http api 搜索数据库并在网站上显示结果。调用需要授权:
$headers = array ('headers' => array(
'Authorization' => 'bearer' . $token ,
'Content-type' => 'application/json',
'Accept' => 'application/json'));
我的搜索表单如下所示:
<form method="GET" accept="application/json" action="https://example.xx/api/v1/products?page=1&size=5&direction=asc&search=value">
<input type="text" name="search" size="40" maxlength="256" value="" placeholder="testsearch">
<input type="submit" name="search_button" value="Search">
</form>
当我在输入字段中输入内容并点击提交按钮时,浏览器会显示:
{"error":"unauthorized","error_description":"Full authentication is required to access this resource"}
在浏览器地址字段中我看到:
https://example.xx/api/v1/products?search=testvalue&search_button=Search
很明显授权被忽略了,url显示我已经离开了我的网站。
我必须使用 action="somephp.php" 来完成这项工作吗? 我如何从表单授权呼叫并在网站上显示响应? 非常感谢提示。神
【问题讨论】: