接收數據,我用下面的發送和接收的數據如下如何發送和捲曲
<?php
$host="localhost";
$username="root";
$password="";
$db_name="test";
mysql_connect("$host", "$username", "$password")or die("cannot connect to server");
mysql_select_db("$db_name")or die("cannot select db");
$query="select * from phone_gap";
$query= mysql_query($query);
while ($row = mysql_fetch_assoc($query)) {
$fields[]=$row;
}
$data['details']=$fields;
$last_name="chaudhary";
$first_name="dharmendra";
//set POST variables
$url = 'http://localhost/test/get-post.php';
//open connection
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $data);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
?>
和GET-post.php中
foreach ($data['details'] as $key => $value) {
print_r($key);
}
如果陣列發送簡單的數據I可以輕鬆取得
$fields = array(
'lname' => urlencode($last_name),
'fname' => urlencode($first_name),
);
$ fields_string ='';
foreach($fields as $key=>$value) {
print_r("$key"." ".$value);
$fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
和GET-出任
的print_r($ _ POST);
有任何解決方案我們可以發送動態數據並檢索它。
感謝和問候。
你是什麼意思的「動態數據」? – gwillie 2014-11-21 06:11:19
只是從表中獲取數據.. – kavita 2014-11-21 06:29:41
你想從curl請求中獲取數據嗎? – Randhir 2014-11-21 07:08:40