更改了标题使用请求,但仍然是text / html

时间:2018-11-30 11:12:42

标签: php http http-headers whmcs

我将PHP请求库用于http请求:

    $url = Qrcode_url;

    $data = array(
        'amount'=> 12,
        'currency'=>'USD',
        'reference'=>'123456765432',
        'ipn_url'=>'http://website.com/ipn'
    );
    // $token
    $headers = array("Authorization" => "Bearer 123456", 'Content-Type' => 'application/json');
    $options = $data;
    $request = Requests::post($url, $headers, array());

    echo '<pre>';
    print_r($request);

这是我屏幕上的输出:

Requests_Response Object
(
    [body] =>  
HTTP Status 415 - 
type Status report

message 

description The server refused this request because the request entity is in a format not supported by the requested resource for the requested method.

Apache Tomcat/7.0.84

    [raw] => HTTP/1.1 415 Unsupported Media Type
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=utf-8
Content-Language: en
Content-Length: 1048
Date: Fri, 30 Nov 2018 11:07:27 GMT
Via: 1.1 google
Alt-Svc: clear
Connection: close


HTTP Status 415 - 
type Status report

message 

description The server refused this request because the request entity is in a format not supported by the requested resource for the requested method.

Apache Tomcat/7.0.84

    [headers] => Requests_Response_Headers Object
        (
            [data:protected] => Array
                (
                    [server] => Array
                        (
                            [0] => Apache-Coyote/1.1
                        )

                    [content-type] => Array
                        (
                            [0] => text/html;charset=utf-8
                        )

                    [content-language] => Array
                        (
                            [0] => en
                        )

                    [content-length] => Array
                        (
                            [0] => 1048
                        )

                    [date] => Array
                        (
                            [0] => Fri, 30 Nov 2018 11:07:27 GMT
                        )

                    [via] => Array
                        (
                            [0] => 1.1 google
                        )

                    [alt-svc] => Array
                        (
                            [0] => clear
                        )

                )

        )

    [status_code] => 415
    [protocol_version] => 1.1
    [success] => 
    [redirects] => 0
    [url] => https://api.ttpay.com/v1.3/transactions/qrcode
    [history] => Array
        (
        )

    [cookies] => Requests_Cookie_Jar Object
        (
            [cookies:protected] => Array
                (
                )

        )

)

上面是错误,您看到我在请求中将Content-Type标头更改为application/json,但是为什么会出现上面的错误?

令牌正确,请注意,错误打印中的请求标头仍为text/html。我该如何解决我的问题?

0 个答案:

没有答案