0

I am calling my java server via PHP and for some reason the PHP sends a GET request instead of POST

I have checked the following links but it doesn't help.

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 Code

<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

Kindly Help !

Community
  • 1
  • 1
Pandeyji
  • 15
  • 7

2 Answers2

0

seems yuo have two form and the second is setted for action="url.php?input" ( a GET param sintax) Due the fact you have input named input you should remove the wrong values

    .....
      <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
  • 131,976
  • 10
  • 91
  • 107
  • 1> Removed the last
    2> Removed action from the Submit button 3> Tried changing to
    – Pandeyji Mar 09 '17 at 08:39
0

Got the fix !

Thanks to @scaisEdge

was the problem (also check my last comment)

If we add method = "post" with action ="url.php" the script sends a POST.

It was sending a GET throughout because I had the without a method and for some reason it was sending GET by default.

Hope it helps the rest !

Pandeyji
  • 15
  • 7