2016-04-05 14 views
1
$file = file_get_contents($path, true); 
$url = "https://secure.efaxdeveloper.com/EFax_WebFax.serv"; 

//setting the curl parameters. 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/x-www-form-urlencoded', 
)); 
// Following line is compulsary to add as it is: 
$data = 'id=' . urlencode("2313125942") . '&name2=' . urlencode($file); 
curl_setopt($ch, CURLOPT_POSTFIELDS,$data); 
$data = curl_exec($ch); 
$info = curl_getinfo($ch); 
curl_close($ch); 
print_r('<pre>'); 
    print_r($info); 
print_r('</pre>'); 

In meinem Code oben stelle ich die Content-Type: application/x-www-form-urlencoded und Post-DatenLocken content_type immer die Standard PHP

$data = 'id=' . urlencode("2313125942") . '&name2=' . urlencode($file); 
curl_setopt($ch, CURLOPT_POSTFIELDS,$data); 

Aber das Ergebnis der curl_getinfo()

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 
) 

Meine Frage, warum content_type ist ist [content_type] => text/html; charset = ISO-8859-1 und ich kann die Post-Daten nicht sehen. Ich bin ein Anfänger in Curl kann jemand erklären, was in meinem Code falsch ist?

+0

Der 'content-type' von' curl_getinfo' ist der Inhaltstyp der Antwort, nicht die Anfrage. Dies bedeutet, dass sie als Antwort auf Ihre HTTP-Anfrage eine HTML-Webseite zurücksenden. Weitere Informationen zu Ihrer Anfrage finden Sie unter 'CURLOPT_VERBOSE' unter http://php.net/curl_setopt. CURL legt außerdem automatisch den Inhaltstyp der Anfrage für Sie fest, sodass Sie ihn nicht angeben müssen, es sei denn, Sie müssen ihn explizit überschreiben. – drew010

+0

Ich möchte alle Informationen über meine Anfrage sehen i dachte curl_getinfo() Funktion wird dies danken Ihnen für diese Information. – Jay

+0

Ich habe versucht, die curl_setopt ($ ch, CURLOPT_VERBOSE, true) Wie kann ich die Informationen meiner Anfrage ausdrucken? – Jay

Antwort

1

Da meine Webanwendung mit Yii-Framework erstellt wird, habe ich stattdessen EHttpClient extension verwendet. @ drew010 Vielen Dank für Ihre Kommentare.

$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"); 

konnte ich meine Anfrage Informationen durch Druck des $ Client w/c das EHttpClient Objekt sehen.

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 
)