0

I'm trying to work with Google's Closure Compiler, unfortunately I stumbled upon a problem with cURL's postfields. It seems to be that when I specify an array here, it doesn't work the way it's supposed to work.

By passing an array to the postfields like this:

curl_setopt($this->curl, CURLOPT_POSTFIELDS, [
    "output_info"       => "compiled_code",
    "output_format"     => "text",
    "compilation_level" => "SIMPLE_OPTIMIZATIONS",
    "js_code"           => urlencode($jsCode),
]);
$result = curl_exec($this->curl);
var_dump($result);

I get an error 13 from Google, indicating I haven't set the output_info parameter. However, when I pass the postfields as a literal string, like the following, everything does work fine and I get the minified JS code in the response.

curl_setopt($this->curl, CURLOPT_POSTFIELDS, 'output_info=compiled_code&output_format=text&compilation_level=SIMPLE_OPTIMIZATIONS&js_code=' . urlencode($jsCode));
$result = curl_exec($this->curl);
var_dump($result);

What am I doing wrong here?

Deltanic
  • 1,009
  • 4
  • 11
  • 17

1 Answers1

0

I think this is a duplicate question. See Google Closure Compiler and multipart/form-data not working.

Long story short - if you pass an array to curl_setopt it will change Content-Type header to multipart/form-data which is not supported by google's API.

Community
  • 1
  • 1
jan.pomahac
  • 101
  • 4