在AppleScript上卷曲

时间:2011-08-23 07:31:02

标签: curl applescript macos

这是我的脚本,但我在从URL获取响应时遇到问题。

if newChromeValue contains "http://" then
        set URLChromerequest to "curl --url http://0.0.0.0:54321/cat?body=" & myBodyEnc & "&url=" & ¬
            newChromeValue & ¬
            "&title=" & ¬
            pgTitlEnc & ¬
            "&keywords=" & ¬
            mykeywordEnc & ¬
            "&description=" & ¬
            myDescriptionEnc & ¬
            "&type=body&reqtype=main/"

    else
        set URLChromerequest to "curl --url http://0.0.0.0:54321/cat?body=" & myBodyEnc & "&url=http://" & ¬
            newChromeValue & ¬
            "&title=" & ¬
            pgTitlEnc & ¬
            "&keywords=" & ¬
            mykeywordEnc & ¬
            "&description=" & ¬
            myDescriptionEnc & ¬
            "&type=body&reqtype=main/"

    end if



    set URLChromeResponse to do shell script URLChromerequest
    return URLChromeResponse

当我运行此脚本时,它显示只有第一个参数通过服务器发送,即'body'。其他人似乎都不见了......

然而,如果我返回'URLChromerequest',我可以看到URL是相应的格式,如果我将其粘贴到Web浏览器,它可以完美地运行..

问题可能是什么?

1 个答案:

答案 0 :(得分:1)

使用quoted form of引用网址可能会有所帮助:

if newChromeValue does not start with "http://" then
    set newChromeValue to "http://" & newChromeValue
end

set URLChromerequest to "curl --url " & quoted form of ¬
    ("http://0.0.0.0:54321/cat?body=" & myBodyEnc & ¬
    "&url=" & newChromeValue & ¬
    "&title=" & pgTitlEnc & ¬
    "&keywords=" & mykeywordEnc & ¬
    "&description=" & myDescriptionEnc & ¬
    "&type=body" & ¬
    "&reqtype=main/")

set URLChromeResponse to do shell script URLChromerequest

虽然不确定,但看起来这个网址被shell分开了