【问题标题】:Use ant,How to open a url with multiple parameters使用ant,如何打开带有多个参数的url
【发布时间】:2012-05-23 18:51:41
【问题描述】:

我正在使用:

<exec executable="cmd">
<arg line="${argLine}" />
</exec>

argLine

<property name="argLine" value="http://127.0.0.1:/product/findSameStyleSku.json?skuId=305&amp;style=120662"/>

有 2 个参数,我使用 &amp;amp; 转义 &amp;amp; 符号

但只打开http://127.0.0.1/product/findSameStyleSku.json?skuId=305

style 参数丢失

总之,我想跑

<target name="111test"> 
    <exec executable="cmd" output="e:/test.txt">
        <arg line="/c start '' 'http://127.0.0.1/product/findSameStyleSku.json?skuId=305&amp;%3bstyle=120662'" />
    </exec>  
</target>

2012-05-23 更新

是的,Windows系统

我把代码改成

<target name="111test">
    <exec executable="cmd" output="e:/test.txt">
        <arg value="/c" />
        <arg value="start" />
        <arg value="" />
        <arg value="http://127.0.0.1/product/findSameStyleSku.json?skuId=305&amp;%3bstyle=120662" />
    </exec>
</target>

运行蚂蚁

只打开

http://127.0.0.1/product/findSameStyleSku.json?skuId=305

我把“&amp;amp;%3b”改成“&amp;amp;

也只能打开

http://127.0.0.1/product/findSameStyleSku.json?skuId=305

但在 cmd 中,我使用

start "" "http://127.0.0.1/product/findSameStyleSku.json?skuId=305&style=120662"

可以打开http://127.0.0.1/product/findSameStyleSku.json?skuId=305&amp;style=120662

【问题讨论】:

    标签: ant


    【解决方案1】:

    不完全理解它试图打开什么。它是真的试图用***?skuId=305 打开一个URL,还是你想说它试图打开你放弃的URL,但不包括分号?

    如果您是说它省略了 URL 的最后一部分,您应该明白分号不能是您发送的实际 URL 的一部分。它们是reserved,必须经过特殊编码。

    确保分号甚至假设存在。当您执行 GET 请求时,您将获得基本 URL,然后在该 URL 之后有一个问号。之后,您有一系列要传递给 URL 的参数,每个参数由 & 号分隔。在您的情况下,您似乎想向 URL 发送请求:

    • http://127.0.0.1:/product/findSameStyleSku.json

    带有以下两个参数:

    • skuId = 305
    • style = 120662

    所以,分号看起来是假的。否则,您将传递参数 ;style 而不是 style。而且,这似乎并不正确。

    如果您确定分号确实存在,请尝试将 URL 中的分号替换为 %3b

    <property name="argLine" value="http://127.0.0.1:/product/findSameStyleSku.json?skuId=305&amp;%3bstyle=120662"/>
    

    响应

    ,对不起,它不能正常工作,我更新了我的问题——感觉

    很遗憾,因为这是在 Windows 机器上,并且是在您的机器上本地运行的东西,所以我自己无法运行测试。

    但是,根据您帖子的第一部分,您正在尝试运行以下命令:

    C> cmd http://127.0.0.1:/product/findSameStyleSku.json?skuId=305&amp;style=120662
    

    在你的帖子后面,你说你想跑步:

    C> cmd /c start '' 'http://127.0.0.1/product/findSameStyleSku.json?skuId=305&amp;%3bstyle=120662'
    

    第一个肯定不会在命令行中工作。第二个呢?

    我用这个在我目前的电脑上做了一些测试:

    <property name="argLine"
        value="http://etzahaim.org/index.php?option=com_content&amp;task=blogcategory&amp;id=15&amp;Itemid=34"/>
    <exec executable="curl">
        <arg value="${argLine}"/>
        <arg value="--include"/>
        <arg value="--output"/>
        <arg value="curl.out"/>
    </exec>
    

    这是获取 URL 的 curl 命令。该 URL 也是使用 GET 方法,因此 URL 中还有一个问号和一些星号。这对我有用。

    尝试从 &lt;arg line='start' '' 'http://...&gt; 切换到使用 &lt;arg line&gt; 看看是否有帮助:

    <target name="111test"> 
        <exec executable="cmd" output="e:/test.txt">
            <arg value="/c"/>
            <arg value="start"/>
            <arg value=""/>
            <arg value="${argline}" />
    </exec>
    

    【讨论】:

    • 我想表达背后的意思,但是,当我执行时,Ant build failed,warn: The reference to entity "amp" must end with the ';'分隔符。
    • @feilong -- 抱歉,我打错了。我将&amp;amp 更改为&amp;amp;。现在答案应该是正确的。
    • @feilong 查看添加到我原始答案中的回复
    • @feilong 我确定我一定在这里遗漏了一些东西。您是否尝试过通过--verbose--debug 开关运行ant,看看这是否为您提供了更多信息。你能用 URL 设置一个属性,然后打印出那个 URL 吗?
    猜你喜欢
    • 2014-08-20
    • 1970-01-01
    • 1970-01-01
    • 2017-11-14
    • 1970-01-01
    • 2020-08-14
    • 2018-06-07
    • 2018-02-21
    • 2013-01-29
    相关资源
    最近更新 更多