【问题标题】:How to Send PHP form POST values to a CGI url?如何将 PHP 表单 POST 值发送到 CGI url?
【发布时间】:2017-03-26 15:22:55
【问题描述】:

我想将 php 值发送到 cgi url

 <form method="post" action="https://192.168.10.1:10443/cgi-bin/outgoingfw.cgi/cgi-bin/outgoingfw.cgi" style="float:left">
                    <input name="ACTION" value="disable" type="hidden">
                    <input name="line" value="0" type="hidden">
                </form>

这些值我想通过 PHP POST 请求发送到 url

https://192.168.10.1:10443/cgi-bin/outgoingfw.cgi

任何人都可以帮助我如何做到这一点。

【问题讨论】:

标签: php forms post request cgi


【解决方案1】:

您缺少提交按钮

  <form action="https://192.168.10.1:10443/cgi-bin/outgoingfw.cgi/cgi-bin/outgoingfw.cgi" method="POST">
       <input type="submit" value="Publish">
       <input name="ACTION" value="disable" type="hidden">
       <input name="line" value="0" type="hidden">
 </form>

更多参考:http://www.comp.leeds.ac.uk/Perl/Cgi/textareas.html

【讨论】:

    【解决方案2】:

    如果您想自动发送。无需按下按钮。否则,为什么需要隐藏字段?

      <form method="post" action="https://192.168.10.1:10443/cgi-bin/outgoingfw.cgi/cgi-bin/outgoingfw.cgi" style="float:left">
            <input name="ACTION" value="disable" type="hidden">
            <input name="line" value="0" type="hidden">
        </form>
        <script>
            document.getElementsByTagName('form')[0].submit();
        </script>
    

    【讨论】:

    • 但价值没有传递任何事情
    • 尝试插入我的代码并在浏览器中打开“网络”,您会看到请求已发送
    • 如果你想在页面上得到答案,那么你需要使用ajax
    • 我尝试了您的代码,但页面重定向到 192.168.10.1:10443/cgi-bin/outgoingfw.cgi 页面但值未通过该页面上没有任何操作
    【解决方案3】:

    只需添加一个“提交”按钮,就可以了。

         <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    <form method="post" action="https://192.168.10.1:10443/cgi-bin/outgoingfw.cgi" style="float:left">
        <input name="ACTION" value="disable" type="hidden">
        <input name="line" value="0" type="hidden">
    
        <!-- submit button -->
        <input type="submit" value="submit"/>
    
    </form>
    </body>
    </html>
    

    【讨论】:

    • 但价值没有传递任何事情
    • 我编辑了我的答案以显示完整的代码。这行得通,我在我的服务器上试过,它可以工作。当然,您只是发布了一个 empy “line” 变量。而且我无权访问您的“192.168.10.1:10443/cgi-bin/outgoingfw.cgi”,所以它只是返回一个错误,但表单已发布
    • 顺便说一句,除非需要,否则不应使用 javascript 发布表单。当你不需要的时候使用 javascript 是一种糟糕的编码,它只会让它变得更复杂、更慢,而且什么都没有
    【解决方案4】:
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-28
    • 1970-01-01
    相关资源
    最近更新 更多