[教程]php模拟get,post表单提交

2014-08-04 02:19:07 -0400
POST代码:
function post( $url, $post )
{
$curl = curl_init( $url );
curl_setopt( $curl, CURLOPT_HEADER, 0 );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $curl, CURLOPT_POST, 1 );
curl_setopt( $curl, CURLOPT_POSTFIELDS, $post );
$result = curl_exec( $curl );
curl_close( $curl );
return $result;
}
GET代码:
function get($url){
$ch = curl_init();
$timeout = 50000;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
$file_contents=mb_convert_encoding($file_contents, "utf-8", "gb2312");
return $file_contents;
}
注:使用上述代码需要网站空间支持curl
«Newer      Older»
Comment:
Name:

Back to home

Subscribe | Register | Login | 中文 | N