Is there an explanation why using array gave me 500 internal server error and using string just works fine with same input ?
$header_array[] = 'Host: example.com';
$header_array[] = 'Accept-Language: tr-TR,tr;q=0.8,en-US;q=0.5,en;q=0.3';
// $header_array[] = 'Accept-Encoding: gzip, deflate';
$header_array[] = 'Connection: keep-alive';
$header_array[] = 'Cache-Control: no-cache';
$header_array[] = 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8';
$header_array[] = 'Pragma: no-cache';
$header_array[] = 'Referer: https://example.com/post/'.$post_id;
$header_array[] = 'X-Requested-With: XMLHttpRequest';
$header_array[] = 'Content-Length: '.strlen("id=".$post_id);
/* curl */
curl_setopt( $ch, CURLOPT_HTTPHEADER, $header_array);
curl_setopt( $ch, CURLOPT_POST, TRUE);
not working (internal server error):
$post_array['id'] = "1";
curl_setopt( $ch, CURLOPT_POSTFIELDS, $post_array);
working:
$post_string = "id=1";
curl_setopt( $ch, CURLOPT_POSTFIELDS, $post_string);
this is also working on another url:
$post_array['__Token'] = $token;
$post_array['UserName'] = $this->username;
$post_array['Password'] = $this->password;
curl_setopt( $ch, CURLOPT_POSTFIELDS, $post_array);
curl verbose output of error:
Array
(
[url] => https://example.com/post/delete
[content_type] =>
[http_code] => 500
[header_size] => 257
[request_size] => 879
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.370037
[namelookup_time] => 2.7E-5
[connect_time] => 0.109487
[pretransfer_time] => 0.187462
[size_upload] => 145
[size_download] => 0
[speed_download] => 0
[speed_upload] => 391
[download_content_length] => 0
[upload_content_length] => 145
[starttransfer_time] => 0.335593
[redirect_time] => 0
[redirect_url] =>
[primary_ip] => 188.132.xx.xxx
[certinfo] => Array
(
)
[primary_port] => 443
[local_ip] => 172.20.xx.xxx
[local_port] => 63696
)
my phpinfo states:
Core
PHP Version => 5.5.14
curl
cURL support => enabled
cURL Information => 7.37.1
http_build_query()on the array you want to send withCURLOPT_POSTFIELDS, e.g.curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_array));$post_stringdoesn't represent the$post_arrayvalues above it so most of that example is irrelevant