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

php curl数据传不过去怎么办

2024/4/16 9:54:47发布20次查看
php curl数据传不过去的解决办法:1、打开相应的php代码文件;2、修改提交方式为“$post_data = username=bob&key=12345;$response = http_req(...);”即可。
本文操作环境:windows7系统、php7.1版,dell g3电脑
php curl数据传不过去怎么办?
php curl post提交数据失败解决方法
代码如下:
function http_req($http_type, $method, $url, $data){ $ch = curl_init(); if (strstr($http_type, 'https')) { curl_setopt($ch, curlopt_ssl_verifypeer, false); curl_setopt($ch, curlopt_ssl_verifyhost, 0); } if ($method == 'post') { curl_setopt($ch, curlopt_post, 1); curl_setopt($ch, curlopt_postfields, $data); } else { $url = $url . '?' . $data; } curl_setopt($ch, curlopt_url, $url); curl_setopt($ch, curlopt_header, 0); curl_setopt($ch, curlopt_returntransfer, 1); curl_setopt($ch, curlopt_timeout, 100000);//超时时间 try { $ret = curl_exec($ch); } catch (exception $e) { curl_close($ch); return json_encode(array('ret' => 0, 'msg' => 'failure')); } curl_close($ch); return $ret;} //第一种提交方式在遇到post_data 中包含@等一些符号时会出现提交失败的情况 $url = "http://localhost/web_services.php"; $post_data = array ("username" => "bob","key" => "12345"); $response = http_req('http', 'post', $url, $post_data ); //第二种提交方式可以避免 $url = "http://localhost/web_services.php"; $post_data = "username=bob&key=12345"; $response = http_req('http', 'post', $url, $post_data );  
推荐学习:《php视频教程》       
以上就是php curl数据传不过去怎么办的详细内容。
该用户其它信息

VIP推荐

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