【问题标题】:GET sent instead of POST HTML->PHP->JSP发送 GET 而不是 POST HTML->PHP->JSP
【发布时间】:2017-03-09 08:23:53
【问题描述】:

我通过 PHP 调用我的 java 服务器,由于某种原因,PHP 发送了一个 GET 请求而不是 POST

我检查了以下链接,但没有帮助。

1> HTML form acting as get instead of post

2>Form sends GET instead of POST

3> Form sends a GET instead of POST

HTML 代码

<html>
<head>
<meta charset="UTF-8">
<title>Cloud Computing</title>

</head>
<body>
<form action="url.php">
<table border="0">
<tr> 
    <td>Input</td>
    <td align="center"><input type="text" name="input" size="30" /></td>
</tr>
<tr>
    <td colspan="2" align="center"><input type="submit"  onclick="url.php?input" action="url.php?input" method="post"/></td>
</tr>

</table>

<form action="url.php?input" method="post"></form>
</body>
</html> 

PHP 代码

<html>
 <head>
 <meta charset="UTF-8">
  <title>PHP Test</title>
 </head>
 <body>
<font face="century gothic" size="20px">
    <center> </br></br>
    <?php 
        echo "Query:";
        echo $_GET["input"]; 
        echo $_POST["input"];
        $input = $_GET["input"]; 
        //echo file_get_contents("http://localhost:8080/CloudComputingProj/Cloudpi");
        # WARNING : maybe you should provide your context in the URL : provide the same URL that you use in your browser for example
        $url = "http://127.0.0.1:8080/CloudComputingProj/Cloudpi";

        $post_params_s = ["input"=>$input];
        //echo post_params_s;
        $ch  = curl_init ( $url ) ;
        curl_setopt ( $ch, CURLOPT_POST          , TRUE ) ;
        curl_setopt ( $ch, CURLOPT_POSTFIELDS    , $post_params_s ) ;
        curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, TRUE ) ;             // -- put it to FALSE, write directly in main output
        curl_exec   ( $ch ) ;
        curl_close  ( $ch ) ;
?></center>
</font>

 </body>
</html>

Webhost error image

Eclipse output for request.getMethod

请帮助!

【问题讨论】:

    标签: php html jsp server


    【解决方案1】:

    似乎 yuo 有两种形式,第二种是为 action="url.php?input" 设置的(一个 GET 参数 sintax) 由于您输入了名为input 的事实,您应该删除错误的值

        .....
          <form action="url.php" method="post">
                <table border="0">
                <tr> 
                    <td>Input</td>
                    <td align="center"><input type="text" name="input" size="30" /></td>
                </tr>
                <tr>
                    <td colspan="2" align="center"><input type="submit"  onclick="url.php?input" action="url.php?input" method="post"/></td>
                </tr>
    
                </table>
    
          </form>
    </body>
    

    【讨论】:

    • 1> 删除了最后一个
      2> 从提交按钮中删除了操作 3> 尝试将 更改为
    【解决方案2】:

    解决了!

    感谢@scaisEdge

    是问题所在(也请查看我的上一条评论)

    如果我们添加 method = "post" 和 action ="url.php",脚本会发送一个 POST。

    它一直在发送 GET,因为我没有方法,并且由于某种原因它默认发送 GET。

    希望对其他人有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-20
      • 1970-01-01
      • 2012-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-23
      • 1970-01-01
      相关资源
      最近更新 更多