簡體   English   中英

php file_get_contents向Bugzilla安裝發送錯誤的內容類型

[英]php file_get_contents sending wrong content-type to a Bugzilla install

我正在創建一個腳本,該腳本應該向bugzilla安裝發送請求,以便登錄用戶並發布錯誤。

我使用的是Google Code上的BugzillaPHP http://code.google.com/p/bugzillaphp/所有在我的本地服務器上工作正常但在運行腳本的遠程服務器上沒有。

我從Bugzilla回來的錯誤是:

Content-Type必須是'text / xml','multipart / *,''application / soap + xml,''或'application / dime'而不是'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',
        '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);

您應該將標頭存儲在數組中。

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

注意標題值末尾的\\r\\n

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM