title: Force service to return json instead of default html
body: <p>I want to be able to code in php the equivalent to this curl command:</p>
  
  <pre><code>curl -F out=json --form-string 'content=&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;title&gt;check it&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&lt;/body&gt;&lt;/html&gt;' http://validator.w3.org/nu/ 
  </code></pre>
  
  <p>This curl command returns json as expected.
  Maybe I am missing something from their documentation here:
  <a href="https://github.com/validator/validator/wiki/Service:-Input:-POST-body" rel="nofollow">https://github.com/validator/validator/wiki/Service:-Input:-POST-body</a> and <a href="https://github.com/validator/validator/wiki/Service%3A-HTTP-interface" rel="nofollow">https://github.com/validator/validator/wiki/Service%3A-HTTP-interface</a></p>
  
  <p>The problem that I have now is that the web service returns html instead of json.
  Although I am setting the header accept to json it does not work. I also tried to set both accept and Content-Type but this triggers an error from the web service saying non valid input. Here is the code that I need your help with:</p>
  
  <pre><code>$html = "&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;title&gt;test&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&lt;/body&gt;&lt;/html&gt;";
  $endPoint = "http://validator.w3.org/nu/";
  $timeout = 5000;
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $endPoint);
  curl_setopt($ch, CURLOPT_TIMEOUT_MS, $timeout);
  curl_setopt($ch,CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
  curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
  //curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Type: application/json'));
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
  curl_setopt($ch,CURLOPT_POSTFIELDS, array('content' =&gt; $html, 'out' =&gt; 'json'));
  $output = curl_exec($ch);
  if(curl_errno($ch))
  {
      echo curl_error($ch);
  }
  curl_close($ch);    
  error_log(__FILE__. ": " . __LINE__ . ": " . var_export($output, true));
  echo $output;
  </code></pre>
  
  <p>After reading Ignacio question I am updating with this information from w3c documentation page:</p>
  
  <p>In their documentation they say the html string should be sent in http body and in their java library they are using this:</p>
  
  <pre><code>String response = null;
  String source = "your html here";
  HttpResponse&lt;String&gt; uniResponse = Unirest.post("http://localhost:8080/vnu")
      .header("User-Agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36")
      .header("Content-Type", "text/html; charset=UTF-8")
      .queryString("out", "gnu")
      .body(source)
      .asString();
  response = uniResponse.getBody();
  </code></pre>
  
  <p>Could this be a hint for you? Just to let you know I tried both</p>
  
  <pre><code>http://validator.w3.org/nu/?out=json
  </code></pre>
  
  <p>and</p>
  
  <pre><code>http://validator.w3.org/nu/
  </code></pre>
  
  <p>endpoints (as value of $endPoint variable in php script above).</p>