一个CURL例子

                $host = APP_DEV ? 'ecode.com' : 'ecode.yinuoinfo.com';
                $uri  = 'http://' . $host . '/ApiJsonTicket/sendticket';
                $ch   = curl_init();
                curl_setopt($ch, CURLOPT_URL, $uri);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
                curl_setopt($ch, CURLOPT_TIMEOUT, 30);
                curl_setopt($ch, CURLOPT_POST, true);
                curl_setopt($ch, CURLOPT_POSTFIELDS, array(
                    'json' => json_encode($apiPost)
                ));
                $HttpResponse = curl_exec($ch);
                curl_close($ch);

上面这种方式可以在php中访问另外的一个页面并返回一个数据。

posted @ 2013-05-06 14:46  linksgo2011  阅读(115)  评论(0)    收藏  举报