发送GET而不是POST HTML-> PHP-> JSP

时间:2017-03-09 08:23:53

标签: php html jsp server

我通过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 CODE

<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

请帮助!

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

得到了修复!

感谢@scaisEdge

是问题(也检查我的上次评论)

如果我们添加方法=&#34; post&#34; with action =&#34; url.php&#34;脚本发送一个POST。

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

希望它有所帮助!