Php Curl添加参数 [英] Php Curl adding Params

查看:165
本文介绍了Php Curl添加参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



有一个单独的函数,它有一个单独的函数添加参数?

 <?php 
$ time = time();
$ message =hello world;


$ urlmessage = urlencode($ message);

$ ch = curl_init(http://mysite.php?message = $ urlmessage& time = $ time);

curl_setopt($ ch,CURLOPT_HEADER,0);

curl_exec($ ch);
curl_close($ ch);
?>

任何人都可以指向正确的方向?

解决方案

您需要 curl_setopt()与CURLOPT_POSTFIELDS参数。
将给定的params POST到目标页面。



curl_setopt($ ch,CURLOPT_POSTFIELDS,'foo = 1& bar = 2& baz = 3');



PS:也可以选中 http_build_query(),当发送很多变量时很方便。


Im a newbie im trying to get a script to trigger another script with Curl in PHP but it dosent seem to be sending the paramaters.

Is there a seperate function to append parameters?

<?php
$time = time();
$message = "hello world";


$urlmessage =  urlencode( $message );

$ch = curl_init("http://mysite.php?message=$urlmessage&time=$time");

curl_setopt($ch, CURLOPT_HEADER, 0);

curl_exec($ch);
curl_close($ch);
?>

Could anyone point me in the right direction??

解决方案

You need curl_setopt() along with the CURLOPT_POSTFIELDS param. That'll POST the given params to the target page.

curl_setopt($ch, CURLOPT_POSTFIELDS, 'foo=1&bar=2&baz=3');

PS: also check http_build_query() which is handy when sending many variables.

这篇关于Php Curl添加参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆