2013-08-06 39 views
0

我想知道,在PHP中是否有可能發送一個post請求到另一個沒有窗體(只是參數)的網站,如在JavaScript中的xmlhttprequest?如果是這樣會怎麼樣?我會欣賞一些例子。我認爲這是捲曲,所以在這種情況下,我將如何發送以下參數: name = bob & lastname = tim通過發送請求到www.example.com使用curl在php中?發送請求到網站通過PHP(類似於xmlhttprequest)

回答

0

試試這個:

$fields_string = "name=bob&lastname=tim"; 
$ch = curl_init(); 
curl_setopt($ch,CURLOPT_URL, "http://www.example.com"); 
curl_setopt($ch,CURLOPT_POST, true); 
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string); 
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true); 
$result = curl_exec($ch); 
相關問題