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_PO*本文来源gaodai#ma#com搞@代~码^网+搞代gaodaima码ST, 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都不用担心了.
——解决方案——————–
简单点正则之,
preg_match(‘/(.*?)<\/response>/s’,$xml,$m);
echo $m[1];
——解决方案——————–
——解决方案——————–
simplexml
——解决方案——————–
顶6楼 正则很强大