1. 程式人生 > >PHP CURL POST提交

PHP CURL POST提交

 
$_post_url = 'http://XXXXX/XXX';
	
	$post = 'key=12&content_id='.$content_id.'&md5='.$storeStatusArr['insert_md5'].'&url='.$url;
	
	$curl = curl_init ( $_post_url );
	curl_setopt ( $curl, CURLOPT_HEADER, 0 );
	$header = array ();
	$header [] = 'Host:www.XXXX.co';
	$header [] = 'Connection: keep-alive';
	$header [] = 'User-Agent: ozilla/5.0 (X11; Linux i686) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.186 Safari/535.1';
	$header [] = 'Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
	$header [] = 'Accept-Language: zh-CN,zh;q=0.8';
	$header [] = 'Accept-Charset: GBK,utf-8;q=0.7,*;q=0.3';
	$header [] = 'Cache-Control:max-age=0';
	$header [] = 'Cookie:t_skey=p5gdu1nrke856futitemkld661; t__CkCkey_=29f7d98';
	$header [] = 'Content-Type:application/x-www-form-urlencoded';
	curl_setopt ( $curl, CURLOPT_HTTPHEADER, $header );
	curl_setopt ( $curl, CURLOPT_POST, 1);
	curl_setopt ( $curl, CURLOPT_POSTFIELDS, $post );
	$result = curl_exec ( $curl );
	curl_close ( $curl );
	var_dump ( $result );

CURLOPT_POSTFIELDS引數使用陣列和字串時的不同

如果是是一個數組,則,

content_type自動為multipart/form-data

提交過去的是原始post,用$_POST[key]是無法獲取

如果是字串。

則反之。