我正在尝试构建一个发布其他web服务的php脚本,我正在使用culr,你可以看到,问题是在API webserver docs中要求我发送一些头参数,字面意思是"对于每个http调用,你需要添加以下标头参数:APIuserID,APIpassword和ResponseType"
所以我的问题是如何将自定义参数添加到我的标头请求?谢谢
<?php
function curl_post($url, array $post = NULL, array $options = array())
{
$defaults = array(
CURLOPT_POST => 1,
CURLOPT_HEADER => 0,
CURLOPT_URL => $url,
CURLOPT_FRESH_CONNECT => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FORBID_REUSE => 1,
CURLOPT_TIMEOUT => 4,
CURLOPT_SSL_VERIFYHOST=>0,
CURLOPT_POSTFIELDS => http_build_query($post)
);
$ch = curl_init();
curl_setopt_array($ch, ($options + $defaults));
if( ! $result = curl_exec($ch))
{
trigger_error(curl_error($ch));
}
curl_close($ch);
return $result;
}
$result=curl_post('https://www.serverPath/serverAPI',array('a'=>'a','b'=>'b'));
echo $result;
Run Code Online (Sandbox Code Playgroud)
?>
您是否尝试过将这些参数添加到httpheader?
curl_setopt($tuCurl, CURLOPT_HTTPHEADER, array(
"Content-Type: text/xml",
"APIuserID: $id",
"APIpassword: $password",
"Content-length: ".strlen($data)
));
Run Code Online (Sandbox Code Playgroud)
另外,您可以使用:http://php.net/manual/en/soapheader.soapheader.php
| 归档时间: |
|
| 查看次数: |
11274 次 |
| 最近记录: |