php中模拟POST传递数据的两种方法分享
2018-10-12 13:56
851 查看
方法1
方法2
$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);
您可能感兴趣的文章:
相关文章推荐
- php中模拟POST传递数据的两种方法分享
- php中模拟POST提交数据两种方法
- php中模拟POST提交数据两种方法
- 如何用PHP模拟POST方法 采集提交后的数据
- 三种方法教你如何用PHP模拟post提交数据
- php 分页显示数据 post参数传递问题解决方法
- php 分页显示数据 post参数传递问题解决方法
- php模拟GET与POST向微信接口提交及获取数据的方法
- PHP中模拟post提交数据的方法
- PHP模拟post提交数据方法汇总
- PHP中使用curl及代理IP模拟post提交【两种实用方法】
- PHP使用$_POST传递数据并检验输出时弹出CSS代码的解决方法
- PHP中 大form用post方法传递数据丢包
- PHP模拟POST提交数据并获得返回值之CURL方法(使用PHP extension,然后使用php_curl.dll,很不错)
- php使用CURL模拟GET与POST向微信接口提交及获取数据的方法
- php模拟post提交数据的方法
- PHP模拟POST提交数据并获得返回值之CURL方法
- php模拟post提交数据的方法
- php 模拟POST提交数据的2种方法
- php模拟POST请求的两种方法