PHP Ï CURL ͨ¹ý POST Ìá½»±íµ¥Ê§°ÜµÄÔÒòÖ®Ò»Óë½â¾ö°ì·¨
Ç°¼¸ÌìÔÚѧϰʹÓà CURL ʱÓöµ½Ò»¸öÎÊÌ⣺ÔÚ a.php ÖÐÒÔ POST ·½Ê½Ïò b.php Ìá½»Êý¾Ý£¬µ«ÊÇ b.php ϾÍÊÇÎÞ·¨½ÓÊÕµ½Êý¾Ý£¬¶ø CURL ²Ù×÷ÓÖÏÔʾ³É¹¦£¬·Ç³£¹îÒì¡£ºó¾¶à·½²éÕÒ£¬ÔÚij¸öÍøÓѵIJ©¿ÍÖеõ½ÁËÆô·¢¡£ÔÀ´£¬¡°´«µÝÒ»¸öÊý×éµ½CURLOPT_POSTFIELDS£¬cURL»á°ÑÊý¾Ý±àÂë³É multipart/form-data£¬¶øÈ»´«µÝÒ»¸öURL-encoded×Ö·û´®Ê±£¬Êý¾Ý»á±»±àÂë³É application/x-www-form-urlencoded¡£
¡±£¬¶øºÍÎÒÒ»Ñù¶Ô CURL ²»Ì«ÊìϤµÄÈËÔÚ±àд³ÌÐòʱ£¬´úÂëÍùÍùÊÇÏÂÃæµÄÑù×Ó£º
$data = array( 'Title' => $title, 'Content' => $content, 'ComeFrom' => $comefrom );
curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false);
curl_setopt($ch, CURLOPT_URL, 'http://example.com/b.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_exec($ch);
Ò² ¾ÍÊǽ«ËùÒªÌá½»µÄÊý¾ÝÒÔÊý×éµÄÐÎʽͨ¹ý POST ·¢ËÍ£¬¶øÕâÑù¾Í»áµ¼Ö CURL ʹÓá°´íÎ󡱵ıàÂë¡°multipart/form-data¡±£¬ÆäЧ¹ûÏ൱ÓÚÎÒÃÇÖ±½ÓÒÔ¡°<form method="post" action="b.php" enctype="multipart/form-data">¡±ÕâÑùµÄ±íµ¥À´Íê³É²Ù×÷£¬´ó¼Ò¿ÉÒÔÊÔÊÔ£¬ÕâʱµÄ¡°b.php¡±ÊÇÎÞÂÛÈçºÎÒ²ÎÞ·¨Í¨¹ý $_POST À´½ÓÊÕÊý¾ÝµÄ¡£
ËùÒÔ£¬ÕýÈ·µÄ×ö·¨Ó¦¸ÃÊǽ«ÉÏÊö·¶Àý´úÂëÖÐµÄ $data ÓÉÊý×é±äΪ¾ urlencode() ±àÂëºóµÄ×Ö·û´®Á¬½Ó£¬ÀàËÆ£º
$data = 'Title=' .urlencode($title) . '&Content=' .urlencode($content) . '&ComeFrom=' .urlencode($comefrom);
ÕâÑù¾Í¿ÉÒÔÁË¡£
×¢Ò⣺Á½ÖÖ·¢ËͱàÂë¸ñʽµÄÇø±ð£¬"multipart/form-data" ÊÇ°Ñ±íµ¥ÉèÖÃΪMIME±àÂ룬ĿµÄÊÇÓÃÀ´´«Êä¶þ½øÖÆÎļþµÄ£¬ÈôÏëÉÏ´«Îļþ£¬±ØÐëÓÃÕâ¸ö±àÂë¡£µ«ÊÇÆÕͨµÄurlÊý¾ÝrequestʹÓõÄÊÇ¡°application/x-www-form-urlencoded¡± ¸ñʽ£¬ ËùÒÔÈç¹û´«ÆÕͨÊý¾ÝÓÃ2½øÖƸñʽ£¬¶Ô·½¾ÍÎÞ·¨µÃµ½ÖµÁË¡£ËùÒÔÌرð×¢ÒâÓ¦¸Ã½«·¢ËÍÇëÇóµÄ±àÂëÈ·¶¨¡£
˳±ãÔټǼһÏÂechoºÍprint_r£¨£©µÄÇø±ð£¬Ò»°ã×ÜÊÇÓÃechoÀ´Êä³öÒ»¸ö±äÁ¿£¬±ÈÈç
echo $data;
echo " i am a fool!!!";
echoÖ÷ÒªÓÃÀ´Êä³ö×Ö·û´®£¬»òÕß±äÁ¿£¬²»ÄÜÓÃÓÚÖ±½ÓÊä³öÊý×é
print_r£¨£©ÊÇÒ»¸öº¯Êý£¬×¨ÃÅÓÃÀ´Ö±½ÓÊä³öÊý×éµÄ£¬±ÈÈç
print_r($array); Ëû»á°´ÕÕÒ»¶¨µÄ¸ñʽ£¬°ÑÊý×éµÄ±êºÅºÍÄÚÈÝ´òÓ¡³öÀ´¡£
ÍƼöÐÅÏ¢
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- php³£ÓÃÕýÔò±í´ïʽ
- phpÐÔÄܼà²âÄ£¿éXHProf
- ÈÃCI¿ò¼ÜÖ§³Öservice²ã
- ʹÓÃPHPÉú³É´øLOGOµÄ¸öÐÔ»¯¶þάÂëͼÏñ
- ¹ØÓÚCodeIgniterÄã¿ÉÄܲ»ÖªµÀµÄ5¸ö֪ʶµã
- Memcache ºÁÃ뼶³¬Ê±¼°ÆäËû³£¼ûÎÊÌâ»ã×Ü
- [PHP±Ê¼Ç]PHPQueryÒ»¸ö´¦ÀíDOMµÄÀûÆ÷
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- PHP»ñÈ¡Óû§µÄÕæʵIP£¬²¢ÅжÏÊÇ·ñÄÚÍøIP
- PHP ´íÎóÈÕÖ¾ error_log
- ÀûÓÃbigpipe»úÖÆʵÏÖÒ³ÃæÄ£¿éµÄÒì²½äÖȾ chunked¼¼Êõ
- php¿ØÖÆÎļþÏÂÔØËÙ¶È
- js + php ¶ÁÈ¡¡¢²¥·ÅÊÓƵÁ÷ ¼æÈÝfirefox£¬c....
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- UNICODE Óë UTF-8 µÄ¹Øϵ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- phpʹÓÃmb_detect_encoding¼ì²â×Ö·û´®±àÂë
ÆÀÂÛ