【问题标题】:using windows system command line to run url in matlabmatlab中使用windows系统命令行运行url
【发布时间】:2018-06-09 08:51:25
【问题描述】:

如何在 Windows 8.1 中使用 MATLAB 运行 curl。 以下代码不起作用:

system(curl(url))

如果我必须使用“https://”或“www”。在网址的开头?不知道有什么区别?

【问题讨论】:

    标签: matlab curl system


    【解决方案1】:

    Matlab system 函数需要您要以字符串形式执行的命令:system('command'),参见help system。按照你的写法,它会执行 Matlab curl 函数,它是一个向量运算符,而不是操作系统函数。

    另外,curl 语法错误,应该是curl url。所以它看起来像这样:system('curl url'),您将 url 替换为您的 URL 文本。如果你想让url 成为一个变量,你可以使用url = 'http://www.google.com'; system(sprintf('curl %s',url))

    当然,您需要确保您的系统上有一个有效的curl

    【讨论】:

      【解决方案2】:

      正如 Lukas 所指出的,当您编写 system(curl(url)) 时,您实际上是在调用 curl Matlab 函数。

      使用 Matlab 执行curl 请求的正确语法:

      command = 'curl http://www.google.com';
      response = system(command);
      

      response 将包含请求响应。您可以在命令字符向量中为您的请求指定任何其他标志。要成功执行系统命令,您的路径中必须包含curl。要确认这一点,请打开终端并输入 curl

      请注意,从 Matlab 2014b 开始,您可以使用 webread 执行 GET 和 POST 请求,而从 Matlab 2015b 开始,您可以使用 webwrite 执行 POST 请求。您可以使用weboptions 为请求指定其他参数,包括我在herehere 中解释的其他标头。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-12-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-06
        相关资源
        最近更新 更多