[英]How to maintain cookies during redirects using perl's LWP::UserAgent?
[英]How can I access Closure JavaScript minifier using Perl's LWP::UserAgent?
我正在尝试使“代码关闭”工作,但是不幸的是,总是会引发错误。
这是代码:
use LWP::UserAgent;
use HTTP::Request::Common;
use HTTP::Response;
my $name = 'test.js';
my $agent = new LWP::UserAgent();
$agent->agent("curl/7.21.0 (x86_64-pc-linux-gnu) libcurl/7.21.0 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18");
$res = $agent->request(POST 'http://closure-compiler.appspot.com/compile',
content_type => 'multipart/form-data',
content => [
output_info => 'compiled_code',
compilation_level => 'SIMPLE_OPTIMIZATIONS',
output_format => 'text',
js_code => [File::Spec->rel2abs($name)]
]);
if ($res->is_success) {
$minified = $res->decoded_content;
print $minified;die;
}
我收到以下错误:
错误(13):没有要产生的输出信息,但需要编译。
这是我使用的api参考: http : //code.google.com/intl/de-DE/closure/compiler/docs/api-ref.html
希望任何人都知道这里出了什么问题。 谢谢。
#!/usr/bin/perl
use strict; use warnings;
use File::Slurp;
use LWP::UserAgent;
my $agent = LWP::UserAgent->new;
my $script = 'test.js';
my $response = $agent->post(
'http://closure-compiler.appspot.com/compile',
content_type => 'application/x-www-form-urlencoded',
content => [
compilation_level => 'SIMPLE_OPTIMIZATIONS',
output_info => 'compiled_code',
output_format => 'text',
js_code => scalar read_file($script),
],
);
if ($response->is_success) {
my $minified = $response->decoded_content;
print $minified;
}
输出:
C:\Temp> cat test.js // ADD YOUR CODE HERE function hello(name) { alert('Hello, ' + name); } hello('New user'); C:\Temp> t function hello(a){alert("Hello, "+a)}hello("New user");
将实际代码作为js_code传递以进行编译。 试试(删除form-data content_type标头):
use File::Slurp "read_file";
...
js_code => scalar( read_file($name) ),
我看到您正在尝试使用POST的文件上传功能; 您在API文档中看到什么使您认为可行? 如果那里有东西,我看不到。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.