Reputation: 31
$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 my code above I set the Content-Type: application/x-www-form-urlencoded
and post data
$data = 'id=' . urlencode("2313125942") . '&name2=' . urlencode($file);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
But the result of the 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
)
My question is why content_type is [content_type] => text/html;charset=ISO-8859-1 and i can't see the post data. I'am a beginner in curl can anyone explain what is wrong in my code?
Upvotes: 1
Views: 210
Reputation: 31
Since my web application is built with Yii framework I used EHttpClient extension instead. @drew010 Thank you for your comments.
$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");
I was able to see my request information by print the $client w/c the EHttpClient object.
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
)
Upvotes: 1