Home > Backend Development > PHP Tutorial > php post请求,该如何解决

php post请求,该如何解决

WBOY
Release: 2016-06-13 13:24:02
Original
792 people have browsed it

php post请求
在php里面怎么提交一个post请求,我要请求一个网址,传参数进去。他会返回一个xml格式的文件结果。在php里面怎么post。

------解决方案--------------------
function _xpost($url,$p)
{
$f='';
$data='';
foreach($p as $k=>$v)
{
$data.=$f.$k.'='.urlencode($v);
$f='&';
}

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1); 
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$res = curl_exec($curl);

if(curl_errno($curl))
{
echo 'Curl error: ' . curl_error($curl);
}
curl_close($curl);
return $res;
}

$x=_xpost('http://abc.com/aa.php',array( 'username'=>$uname,
));
------解决方案--------------------
顶一楼 用curl
------解决方案--------------------
xml 请使用simplexml来解析.学好simplexml 以后碰到xml都不用担心了.

探讨

还有个问题请教,如果$x=_xpost('http://abc.com/aa.php',array('username'=>$uname));接收到的数据是一个xml:


1

我怎么获取之间的1这个值?

------解决方案--------------------
简单点正则之,
preg_match('/(.*?)/s',$xml,$m);
echo $m[1];
------解决方案--------------------
探讨

还有个问题请教,如果$x=_xpost('http://abc.com/aa.php',array('username'=>$uname));接收到的数据是一个xml:


1

我怎么获取之间的1这个值?

------解决方案--------------------
simplexml
------解决方案--------------------
顶6楼 正则很强大
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template