如何发送和卷曲
问题描述:
接收数据,我用下面的发送和接收的数据如下如何发送和卷曲
<?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);
有任何解决方案我们可以发送动态数据并检索它。
感谢和问候。
答
$query="select * from phone_gap";
$query= mysql_query($query);
while ($row = mysql_fetch_assoc($query)) {
$fields[]=$row;
}
$str = http_build_query($fields);
$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, $str);
//execute post
$result = curl_exec($ch);
echo $result;
和GET-post.php中使用
回声 “”;的print_r($ _ POST);
+0
在print_r之前使用pre标签 – user3840898 2014-11-21 10:39:17
答
你不必通过后期的多维数组,只需使用卷曲后是这样的:
$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, $fields);
通过您$域变量直接张贴代替$ data数组使用它。这对你有用。
你是什么意思的“动态数据”? – gwillie 2014-11-21 06:11:19
只是从表中获取数据.. – kavita 2014-11-21 06:29:41
你想从curl请求中获取数据吗? – Randhir 2014-11-21 07:08:40