您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php中模拟POST传递数据的两种方法分享

2024/3/26 1:50:05发布105次查看
方法1 
复制代码 代码如下: 
$ch = curl_init(); 
curl_setopt($ch, curlopt_url, http://192.168.1.135/turntable/get_jump.php); 
curl_setopt($ch, curlopt_header, 0); 
curl_setopt($ch, curlopt_postfields, $array); 
curl_exec($ch); 
curl_close($ch);
方法2 
复制代码 代码如下: 
$data['uid'] = $this->uid; 
$data['efforts'] = $res['efforts']; 
$data['breakthrough'] = $res['breakthrough']; 
$data['target'] = $res['target']; 
$str = ''; 
foreach ($data as $k=>$v) { 
if (is_array($v)) { 
foreach ($v as $kv => $vv) { 
$str .= '&' . $k . '[' . $kv . ']=' . urlencode($vv); 

} else { 
$str .= '&' . $k . '=' . urlencode($v); 


$context = 
array('http' => 
array('method' => 'post', 
'header' => 'content-type: application/x-www-form-urlencoded'.\r\n. 
'user-agent: manyou api php client 0.1 (non-curl) '.phpversion().\r\n. 
'content-length: ' . strlen($str), 
'content' => $str)); 
$contextid = stream_context_create($context); 
$sock = fopen('http://192.168.1.135/turntable/get_jump.php', 'r', false, $contextid); 
if ($sock) { 
$result = ''; 
while (!feof($sock)) { 
$result .= fgets($sock, 4096); 

fclose($sock);
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product