2017-07-06 51 views
0
cd /var/www/html/phplearn 

对于http post请求和响应。如何编写curl命令来模拟get方法?

VIM send_local_post.php

<form action=http://127.0.0.1/phplearn/do_post.php method=post> 
user: <input type=text name=userName size=12/> 
key: <input type=text name=PS size=12/> 
<input type=submit value=login> 
</form> 

VIM do_post.php

<?php 
$userName = $_POST["userName"]; 
$PS = $_POST["PS"]; 
echo "the name is: ".$userName."\n"; 
echo "key word is: ".$PS."\n"; 
?> 

让我们模拟的方法后,在控制台卷曲。

curl -X POST -d "userName=user&PS=key" 127.0.0.1/phplearn/do_post.php 

在控制台的输出是如下:

enter image description here

对于HTTP GET请求和响应。

VIM send_local.get.php

<form action=http://127.0.0.1/phplearn/do_get.php method=get> 
user: <input type=text name=userName size=12/> 
key: <input type=text name=PS size=12/> 
<input type=submit value=login> 
</form> 

VIM do_get.php

<?php 
$userName = $_GET["userName"]; 
$PS = $_GET["PS"]; 
echo "the name is: ".$userName."\n"; 
echo "key word is: ".$PS."\n"; 
?> 

让我们模仿get方法与控制台卷曲。

curl http://127.0.0.1/phplearn/do_get.php?userName=user&PS=key 

在控制台的输出是如下:
enter image description here

为什么不能显示在控制台上的键的值,如后方法?

回答

0

这是因为&字符。当bash碰到&符时触发一个后台进程,并切断剩余的文本。

这也是为什么你看到[1] 14975,因为它正在脱离一个新的过程,并在后台运行它。

为了解决这个问题,只需附上您的网址报价:

curl "http://127.0.0.1/phplearn/do_get.php?userName=user&PS=key"