cURL不适用于Flex(as3)

时间:2013-08-26 11:37:11

标签: actionscript-3 flex curl air

我为笨拙的英语提前道歉) 我在Flex中启动cURL时遇到问题。这是我的代码:

private var process:NativeProcess;
private var file:File = new File();
private var uploadFile:File = new File();
private var username:String = "user";
private var password:String = "pass";
private var server:String = "ftp:\\--.---.---.---";

public var loadingBar:LoadingBar;

private function startUpload(event:Event):void
{
    loadingBar = LoadingBar(PopUpManager.createPopUp( this, LoadingBar, true));
    loadingBar.progressBar.source = process;
    PopUpManager.centerPopUp(loadingBar);

    file.nativePath = "C://curl.exe";
    uploadFile.nativePath = "C://001.mov";

    var arguments:Vector.<String> = new Vector.<String>();
    arguments.push("curl -T " + uploadFile.nativePath + " " + server  + " -u " + username + ":" + password);
    //arguments.push("curl http://isc.sans.org/infocon.txt");
    trace(arguments);

    var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
    nativeProcessStartupInfo.arguments = arguments;
    nativeProcessStartupInfo.executable = file;

    process = new NativeProcess();
    process.start(nativeProcessStartupInfo);

    process.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, onStandardErrorData);
    process.addEventListener(NativeProcessExitEvent.EXIT, onStandardOutputExit);

    process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);

    process.addEventListener(IOErrorEvent.STANDARD_OUTPUT_IO_ERROR, onOutputIOError);
    process.addEventListener(IOErrorEvent.STANDARD_INPUT_IO_ERROR, onInputClose);
    process.addEventListener(IOErrorEvent.STANDARD_ERROR_IO_ERROR, onStandardIOError);
}

standardErrorData发出“%Total%Received%Xferd Average Speed Time Time Time Current

                       Dload  Upload   Total   Spent    Left  Speed

0 0 0 0 0 0 0 0 - : - : - - : - : - - : - : - 0“ 然后 “curl:(6)无法解析主机:curl -T C:\ 001.mov ftp: - 。---。--- .--- -u user”。那是在结肠前切断的,这很奇怪..

如果我使用带有最简单命令的注释行而不是之前的命令,我会收到错误“curl:(1)libcurl中不支持或禁用协议卷曲http。”

我不明白为什么这样,因为命令行相同的命令工作正常!

1 个答案:

答案 0 :(得分:0)

你的参数向量是错误的,你应该为每个参数使用一个单独的条目(不幸的是Adobe Live Docs并不十分清楚它是如何看起来的那样),也没有必要通过{{1}作为参数,该进程已经知道可执行文件。

curl

确保

var arguments:Vector.<String> = new Vector.<String>();
arguments[0] = '-T';
arguments[1] = uploadFile.nativePath;
arguments[2] = server;
arguments[3] = '-u';
arguments[4] =  username + ':' + password;

实际上是正确的格式。至少the manual中的示例有点不同,它们看起来像

curl -T uploadfile server -u user:passwd

不确定这是否有所作为。