0
這個API讓我頭疼..真的無法弄清楚什麼是錯在這裏..API谷歌Closure編譯器
它只是通過回這個錯誤:
414. That’s an error.
The requested URL /compile... is too large to pr
文件$filename
存在時回聲線是轉義
代碼
$Compile = new Net_minify_JS();
$Compile->script = file_get_contents($filename);
//echo $Compile->script;
$Compile->content_length = strlen($Compile->script);
echo '<pre>';
echo $Compile->get();
echo '</pre>';
class Net_minify_JS extends Net_socket {
private $content = null;
public $script = '';
function get(){
$this->url = 'closure-compiler.appspot.com';
$this->path = '/compile?output_info=compiled_code&output_format=text&compilation_level=SIMPLE_OPTIMIZATIONS&js_code='.urlencode($this->script);
$this->method = 'POST';
$this->connect();
$this->content = $this->get_content();
$string = str_replace("\r\n", "\n", $this->content);
return $string;
}
}
class Net_socket {
public $url = null;
public $path = null;
public $method = 'GET';
public $content_type = 'application/x-www-form-urlencoded';
public $content_length = 0;
public $port = 80;
public $timeout = 20;
private $fp = null;
private $response = null;
function connect(){
$this->response = null;
$this->method = $this->prepare_method();
if($this->fp = fsockopen($this->url, $this->port, $errno, $errstr, $this->timeout)){
$write = "$this->method $this->path HTTP/1.1\r\n";
$write .= "Host: $this->url\r\n";
$write .= "Content-Type: $this->content_type\r\n";
$write .= $this->content_length ? "Content-Length: $this->content_length\r\n":'';
$write .= "Connection: Close\r\n\r\n";
fwrite($this->fp, $write);
while($line = fgets($this->fp)){
if($line !== false) $this->response .= $line;
}
fclose($this->fp);
}
else{
//echo "$errstr ($errno)<br>\n";
}
}
function prepare_method(){
return strtoupper($this->method);
}
function get_content(){
$this->response = str_replace("\r\n", "\n", $this->response);
$expl = explode("\n\n", $this->response);
return $expl[1];
}
}
通過在POST中傳遞js_code,你是什麼意思?所有的變量都作爲POST方法傳遞 – clarkk 2012-02-26 09:32:47