gpt4 book ai didi

php file_get_contents 向 Bugzilla 安装发送错误的内容类型

转载 作者:可可西里 更新时间:2023-10-31 23:23:58 24 4
gpt4 key购买 nike

我正在创建一个脚本,该脚本应向 bugzilla 安装发送请求,以便登录用户并发布错误。

我正在使用 Google 代码上提供的 BugzillaPHP http://code.google.com/p/bugzillaphp/在我的本地服务器上一切正常,但在应该运行脚本的远程服务器上却不行。

我从 Bugzilla 返回的错误是:

Content-Type must be 'text/xml,' 'multipart/*,' 'application/soap+xml,' 'or 'application/dime' instead of 'application/x-www-form-urlencoded'

这意味着我的脚本在 header 中发送了错误的内容类型(或者 Bugzilla 错误地检测了 header )。但是我很确定内容类型设置为正确的值。这是我的代码:

    $context = stream_context_create(array('http' => array(
'method' => 'POST',
'header' => 'Content-Type: text/html',
'content' => $body
)));


$response = file_get_contents($url, false, $context);

有什么想法吗?

最佳答案

您的远程服务器的 php 版本是多少? 5.2 中有一个错误会阻止发送 header 。在stream_context_create之前需要在ini_set中添加:

    $params = array('http' => array(
'method' => 'POST',
'header' => 'Content-Type: text/html',
'content' => $body
));

// workaround for php bug where http headers don't get sent in php 5.2
if(version_compare(PHP_VERSION, '5.3.0') == -1){
ini_set('user_agent', 'PHP-SOAP/' . PHP_VERSION . "\r\n" . $params['http']['header']);
}

$context = stream_context_create($params);
$response = file_get_contents($url, false, $context);

关于php file_get_contents 向 Bugzilla 安装发送错误的内容类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9976043/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com