【发布时间】:2015-07-23 07:26:31
【问题描述】:
我正在使用 curl 进行 api 调用,并且我正在发送“X_ACCESSKEY”作为标题。 以下是我的代码
$url = "http://127.0.0.1:8080/user/getheader";
$data=array();
$data = json_encode($data);
$ch = curl_init($url);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $data );
$headers = array('Content-Type:application/json','X_ACCESSKEY: 1234');
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
# Return response instead of printing.
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
# Send request.
$result = curl_exec($ch);
curl_close($ch);
现在我想获取“http://127.0.0.1:8080/user/getheader”中的“X_ACCESSKEY”标头值
【问题讨论】:
-
你能再澄清一下你的问题吗?
-
我正在使用 curl 将标头值发送到 api,我需要在 api 文件中获取这些标头值。 HEADERS : $headers = array('Content-Type:application/json','X_ACCESSKEY: 1234');我想在我的 api 文件中将 ACCESSKEY 设为“1234”。