Curl content_type始终是默认的php

时间:2016-04-05 04:25:28

标签: php curl

Content-Type: application/x-www-form-urlencoded

在上面的代码中,我设置了$data = 'id=' . urlencode("2313125942") . '&name2=' . urlencode($file); curl_setopt($ch, CURLOPT_POSTFIELDS,$data); 并发布了数据

Array
(
    [url] => https://secure.efaxdeveloper.com/EFax_WebFax.serv
    [content_type] => text/html;charset=ISO-8859-1
    [http_code] => 200
    [header_size] => 226
    [request_size] => 175
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 0.65944
    [namelookup_time] => 0.150319
    [connect_time] => 0.183032
    [pretransfer_time] => 0.261438
    [size_upload] => 531848
    [size_download] => 833
    [speed_download] => 1263
    [speed_upload] => 806514
    [download_content_length] => 833
    [upload_content_length] => 531848
    [starttransfer_time] => 0.293966
    [redirect_time] => 0
    [redirect_url] => 
    [primary_ip] => 104.12.131.61
    [certinfo] => Array
        (
        )

    [primary_port] => 443
    [local_ip] => 127.31.12.152
    [local_port] => 52972
)

但是curl_getinfo()

的结果
@Table

我的问题是为什么content_type是[content_type] => text / html; charset = ISO-8859-1,我看不到帖子数据。我是卷曲的初学者,任何人都可以解释我的代码中有什么问题吗?

1 个答案:

答案 0 :(得分:1)

由于我的Web应用程序是使用Yii框架构建的,因此我使用了EHttpClient extension。 @ drew010感谢您的评论。

$file = file_get_contents($path, true);

Yii::import('ext.EHttpClient.*');

$client = new EHttpClient('https://secure.efaxdeveloper.com/EFax_WebFax.serv', array(
    'maxredirects' => 3,
    'timeout'      => 30,
    'Content-Type' => 'application/x-www-form-urlencoded',
    'adapter'      => 'EHttpClientAdapterCurl'));

$client->setParameterPost(array('id'=>urlencode("2313125942"), 'xml'=>urlencode($file)));


SiteHelper::printShow($client);

$response = $client->request("POST");

我可以通过打印带有EHttpClient对象的$ client来查看我的请求信息。

EHttpClient Object
(
    [config:protected] => Array
        (
            [maxredirects] => 3
            [strictredirects] => 
            [useragent] => EHttpClient
            [timeout] => 30
            [adapter] => EHttpClientAdapterCurl
            [httpversion] => 1.1
            [keepalive] => 
            [storeresponse] => 1
            [strict] => 1
            [output_stream] => 
            [encodecookies] => 1
            [rfc3986_strict] => 
            [content-type] => application/x-www-form-urlencoded
        )

    [adapter:protected] => 
    [uri:protected] => EUriHttp Object
        (
            [_username:protected] => 
            [_password:protected] => 
            [_host:protected] => secure.efaxdeveloper.com
            [_port:protected] => 443
            [_path:protected] => /EFax_WebFax.serv
            [_query:protected] => 
            [_fragment:protected] => 
            [_regex:protected] => Array
                (
                    [alphanum] => [^\W_]
                    [escaped] => (?:%[\da-fA-F]{2})
                    [mark] => [-_.!~*'()\[\]]
                    [reserved] => [;\/?:@&=+$,]
                    [unreserved] => (?:[^\W_]|[-_.!~*'()\[\]])
                    [segment] => (?:(?:(?:[^\W_]|[-_.!~*'()\[\]])|(?:%[\da-fA-F]{2})|[:@&=+$,;])*)
                    [path] => (?:\/(?:(?:(?:[^\W_]|[-_.!~*'()\[\]])|(?:%[\da-fA-F]{2})|[:@&=+$,;])*)?)+
                    [uric] => (?:[;\/?:@&=+$,]|(?:[^\W_]|[-_.!~*'()\[\]])|(?:%[\da-fA-F]{2}))
                )

            [_scheme:protected] => https
        )

    [headers:protected] => Array
        (
        )

    [method:protected] => GET
    [paramsGet:protected] => Array
        (
        )

    [paramsPost:protected] => Array
        (
            [id] => 2313125942
            [xml] => The%encoded%url%xml%data
        )

    [cookiejar:protected] => 
    [last_request:protected] => 
    [last_response:protected] => 
    [redirectCounter:protected] => 0
    [_unmaskStatus:protected] => 
    [_queryBracketsEscaped:protected] => 1
)