php怎么写一个发布页面,发布到PHP脚本中的另一个页面

可能最简单的方法使PHP执行POST请求是使用

cURL,作为一个

extension或简单地shelling到另一个进程。这里是一个帖子样例:

// where are we posting to?

$url = 'http://foo.com/script.php';

// what post fields?

$fields = array(

'field1' => $field1,

'field2' => $field2,

);

// build the urlencoded data

$postvars = http_build_query($fields);

// open connection

$ch = curl_init();

// set the url, number of POST vars, POST data

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_POST, count($fields));

curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);

// execute post

$result = curl_exec($ch);

// close connection

curl_close($ch);

还要在Zend框架中检查Zend_Http类的集合,它提供了一个非常强大的HTTP客户端直接用PHP编写(不需要扩展)。

2014 EDIT – 好吧,自从我写了一段时间。这些天值得检查Guzzle,它可以再次使用或不使用curl扩展。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值