我正在使用旧版本的Guzzle(版本3)进行项目开发,我想在发布请求中添加令牌,找不到方法,我查看了文档没有任何例子,这是我到目前为止尝试过的:
this
<?php
$client = new Client();
$client->setDefaultOption('headers', array(
'Authorization' => ['Bearer', $token]
));
$req = $client->post($url);
$client->send($req)->getBody(true);
?>
我不断得到: Guzzle \ Http \ Exception \ ClientErrorResponseException:客户端错误响应[状态码] 400 [原因短语]错误的请求[url]
答案 0 :(得分:0)
我找到了解决方法:
const state = {
tasks: [] // array of objects
task: null
}
const getters = {
task: state => state.task
};
const actions = {
showTaskInForm({ commit, state }, taskId) {
const task = state.tasks.filter(task => task.id === taskId);
const taskToEdit = task.length === 1 && task[0];
commit('showTaskInForm', taskToEdit);
}
};
const mutations = {
showTaskInForm: (state, taskToEdit) => (state.task = taskToEdit)
}
export default {
state,
getters,
actions,
mutations
};
因此,我发送了一个包含令牌的字符串,而不是授权中的数组