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

前端之家收集整理的这篇文章主要介绍了php中模拟POST传递数据的两种方法分享前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

方法1 @H_301_0@<div class="codetitle"><a style="CURSOR: pointer" data="9502" class="copybut" id="copybut9502" onclick="doCopy('code9502')"> 代码如下:

<div class="codebody" id="code9502"> @H_301_0@$ch = curlinit(); @H301_0@curl_setopt($ch,CURLOPT_URL,"http://192.168.1.135/turntable/get_jump.PHP"); @H_301_0@curl_setopt($ch,CURLOPTHEADER,0); @H301_0@curl_setopt($ch,CURLOPTPOSTFIELDS,$array); @H301_0@curlexec($ch); @H301_0@curlclose($ch); @H3010@
@H301_0@方法2 @H_301_0@<div class="codetitle"><a style="CURSOR: pointer" data="1216" class="copybut" id="copybut1216" onclick="doCopy('code1216')"> 代码如下:
<div class="codebody" id="code1216"> @H_3010@$data['uid'] = $this->uid; @H3010@$data['efforts'] = $res['efforts']; @H3010@$data['breakthrough'] = $res['breakthrough']; @H3010@$data['target'] = $res['target']; @H3010@$str = ''; @H3010@foreach ($data as $k=>$v) { @H301_0@if (isarray($v)) { @H3010@foreach ($v as $kv => $vv) { @H3010@$str .= '&' . $k . '[' . $kv . ']=' . urlencode($vv); @H3010@} @H3010@} else { @H3010@$str .= '&' . $k . '=' . urlencode($v); @H3010@} @H3010@} @H3010@$context = @H3010@array('http' => @H3010@array('method' => 'POST',@H3010@'header' => 'Content-type: application/x-www-form-urlencoded'."\r\n". @H301_0@'User-Agent: Manyou API PHP Client 0.1 (non-curl) '.PHPversion()."\r\n". @H_3010@'Content-length: ' . strlen($str),@H3010@'content' => $str)); @H301_0@$contextid = stream_contextcreate($context); @H301_0@$sock = fopen('http://192.168.1.135/turntable/get_jump.PHP','r',false,$contextid); @H_3010@if ($sock) { @H3010@$result = ''; @H3010@while (!feof($sock)) { @H3010@$result .= fgets($sock,4096); @H3010@} @H3010@fclose($sock); @H301_0@

原文链接:https://www.f2er.com/php/27615.html

猜你在找的PHP相关文章