我們知道,在提交表單,如果數據中有特殊字符,比如+號的時候,需要url encode一下,這樣加號就能傳給服務器。
<form action="http://192.168.1.101/savepost.php" method="post">
your data: <input type="text" name="mypost" />
<input type="submit" />
</form>
在input裏輸入數據123+458,提交,服務器收到的數據裏,加號丟失了,變成了空格。
如果我們先對123+458進行url encode,得到這個:123%2B458,再填到input裏,提交,那麼服務器會收到正確的數據。
比如,如下代碼
$data = "mypost=".urlencode("123+458");
$str=curlrequest($url,$data,$proxy);//curlrequest是我用curl庫的一些函數封裝的可用來post數據的函數
這樣會有問題,加號還是丟失了。我們必須這樣:
$data = "mypost=".urlencode(urlencode("123+458"));
$str=curlrequest($url,$data,$proxy);
才能收到正確數據。