GET sent 而不是 POST HTML->PHP->JSP



我正在通过PHP调用我的Java服务器,由于某种原因,PHP发送了Get请求而不是POST

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

1> html表单充当get而不是帖子

2>表格发送而不是发布

3>表格发送get而不是发布

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错误图像

Eclipse for Request.getMethod

请帮助!

似乎有两种形式,第二个形式是为 action="url.php?input"(a get param 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>

得到了修复!

感谢@scaisedge

是问题(也请检查我的最后一个评论)

如果我们添加方法=" post" with action =" url.php"脚本发送帖子。

它在整个过程中都发送了一个get,因为我没有方法,由于某种原因,它默认情况下发送了。

希望它对其余的帮助!

最新更新