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]是无法获取

如果是字符串。

则反之。


 

你可能感兴趣的:(PHP)