加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 16:44:23 所属栏目:PHP教程 来源:网络整理
导读:我正在创建一个脚本,该脚本应该向bugzilla安装发送请求,以便登录用户并发布错误. 我正在使用Google Code http://code.google.com/p/bugzillaphp/上提供的BugzillaPHP 一切都在我的本地服务器上正常工作,但不在运行脚本的远程服务器上运行. 我从Bugzilla回来
我正在创建一个脚本,该脚本应该向bugzilla安装发送请求,以便登录用户并发布错误.

我正在使用Google Code http://code.google.com/p/bugzillaphp/上提供的BugzillaPHP
一切都在我的本地服务器上正常工作,但不在运行脚本的远程服务器上运行.

我从Bugzilla回来的错误是:

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

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

$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中存在阻止发送标头的错误.需要在stream_context_create之前添加到ini_set:

$params = array('http' => array(
        'method' => 'POST','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 . "rn" . $params['http']['header']); 
    } 

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读