【发布时间】:2015-01-08 18:44:58
【问题描述】:
http 连接需要带有自定义标头对象 Authentication-API-Key 的 HTTP POST 请求
使用 CURL,它会自动转换为 [HTTP_AUTHENTICATION_API_KEY] => 12345 不知道为什么
一个用于测试的 php 类的简单摘录是
请帮帮我,如何使用 [Authentication-API-Key] => 123456 获得 $_SERVER 结果
<?php
$contentType = 'text/xml';
$method = 'POST';
$auth = '';
$header1 = 'Authentication-API-Key: 12345';
$charset= 'ISO-8859-1';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://localhost/test/returnurl.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array('Content-type: ' .
$contentType . '; charset=' . $charset,
$header1));
curl_exec($ch);
?>
<?php
//http://localhost/test/returnurl.php
Print_r($_SERVER,true)
?>
输出:
大批 ( [HTTP_HOST] => 本地主机 [HTTP_ACCEPT] => */* [内容类型] => 文本/xml;字符集=ISO-8859-1 [HTTP_AUTHENTICATION_API_KEY] => 12345 ... )【问题讨论】:
-
header2似乎未定义,可能是问题所在? -
您是否尝试过使用
get_headers而不是$_SERVER来读取标题?