title: Php Curl request Content Type header
body: <p>im trying to execute a curl request from my server. In local works perfectly, when i upload the script into the remote server it doesn't work.</p>
  
  <p>This is the code:</p>
  
  <pre><code>$ch = curl_init( $url );
  $payload = json_encode( array( "pIdPostazione"=&gt;4 ) );
  echo $payload;
  curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload );
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
  </code></pre>
  
  <p>On local server this is the header:</p>
  
  <pre><code>Array ( [url] =&gt; http:/xxxxxxx [content_type] =&gt; application/json; charset=utf-8 [http_code] =&gt; 200 [header_size] =&gt; 270 [request_size] =&gt; 151 [filetime] =&gt; -1 [ssl_verify_result] =&gt; 0 [redirect_count] =&gt; 0 [total_time] =&gt; 0.125 [namelookup_time] =&gt; 0 [connect_time] =&gt; 0.062 [pretransfer_time] =&gt; 0.062 [size_upload] =&gt; 19 [size_download] =&gt; 634 [speed_download] =&gt; 5072 [speed_upload] =&gt; 152 [download_content_length] =&gt; 634 [upload_content_length] =&gt; 19 [starttransfer_time] =&gt; 0.125 [redirect_time] =&gt; 0 [redirect_url] =&gt; [primary_ip] =&gt; xxxxx [certinfo] =&gt; Array ( ) [primary_port] =&gt; xxx[local_ip] =&gt; xxxxx [local_port] =&gt; xxxx) 
  </code></pre>
  
  <p>When the script is executed from the remote server the header content type and other header fields are empty:</p>
  
  <pre><code>Array ( [url] =&gt; xxxxx [content_type] =&gt; [http_code] =&gt; 0 [header_size] =&gt; 0 [request_size] =&gt; 0 [filetime] =&gt; -1 [ssl_verify_result] =&gt; 0 [redirect_count] =&gt; 0 [total_time] =&gt; 0.000164 [namelookup_time] =&gt; 4.0E-5 [connect_time] =&gt; 0 [pretransfer_time] =&gt; 0 [size_upload] =&gt; 0 [size_download] =&gt; 0 [speed_download] =&gt; 0 [speed_upload] =&gt; 0 [download_content_length] =&gt; -1 [upload_content_length] =&gt; -1 [starttransfer_time] =&gt; 0 [redirect_time] =&gt; 0 [redirect_url] =&gt; [primary_ip] =&gt; [certinfo] =&gt; Array ( ) [primary_port] =&gt; 0 [local_ip] =&gt; [local_port] =&gt; 0 ) 
  </code></pre>
  
  <p>Why????</p>
  
  <p>These are the versions:<br>
  Local: Php 5.5.30, Curl 7.42.1<br>
  Remote: Php 5.6.21,Curl 7.38.0 </p>
  
  <p>Thanks!</p>
  
  <p>This is the whole code that i use:</p>
  
  <pre><code>$ch = curl_init( $url );
  # Setup request to send json via POST.
  $payload = json_encode( array( "pIdPostazione"=&gt;4 ) );
  curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload );
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
  
  curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
  # Send request.
  $result = curl_exec($ch);
  if ($result === false) $result = curl_error($ch);
  
  
  $info = curl_getinfo($ch);
  print_r($info);        
  curl_close($ch);
  </code></pre>
  
  <p>Another question/info: why from local machine and from my another remote server i can see the request header as follow:</p>
  
  <pre><code> [request_header] =&gt; POST /SFCTIO.asmx/GetNextVar HTTP/1.1 Host: xxx.xxx.xxx.xxx:65080 Content-Type: application/json Accept: application/json Content-Length: 19 ) 
  </code></pre>
  
  <p>and from the server where request return connection refused curl wont print the request header?</p>
  
  <p>I'm confused </p>