【发布时间】:2018-04-24 11:08:20
【问题描述】:
这是我的 JSON 请求示例
{
"Username":"admin",
"Password":"root123",
"PinCode” : "hello321"
}
我也想发布一个请求令牌,请求令牌必须作为请求标头发布。
当我成功发送了这些数据和有效令牌后,我需要收到如下的 jSON 响应,
{
"Title": "Mr.",
"Name": "Pushkov",
"Age": "18"
}
我的问题是,
如果代码点火器中的详细信息错误,我如何在 PHP cURL 中发布我上面提到的 JSON 数据和令牌并显示错误?
这是我到目前为止所做的......它没有给我我正在寻找的确切输出,我无法找到一种方法将我的令牌作为标头请求发送......
public function send_veri(){
$url='http://helloworld21.azurewebsites.net/api/member/login';
$ch = curl_init('http://localhost/apphome');
$data = array("Username" =>$this->input->post('un'), "Password" =>$this->input->post('pw'), "PinCode" =>$this->input->post('VerificationCode'));
$data_string = json_encode($data);
// Disable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set the url
//curl_setopt($ch, CURLOPT_URL,$url);
// Execute
$result=curl_exec($ch);
}
运行此程序后,我只能获取用户名、密码和 PinCode。我无法在我的标头中发布请求令牌,导致我无法获得成员详细信息响应。
【问题讨论】: