Php Curl发布到.aspx
我无法在php中使用curl发布到url:Php Curl发布到.aspx,php,post,Php,Post,我无法在php中使用curl发布到url: post字符串应采用以下模式:example.com/sms/sms.aspx?uid=9746674889&pwd=passwod&phone=9746674889&msg=hjgyjgkjk&provider=way2sms&send=send 如果已发布,则输出将为1 else-1 有人能帮我做卷发吗 <?php //extract data from the post // extract($_GET);
post字符串应采用以下模式:example.com/sms/sms.aspx?uid=9746674889&pwd=passwod&phone=9746674889&msg=hjgyjgkjk&provider=way2sms&send=send 如果已发布,则输出将为1 else-1 有人能帮我做卷发吗
<?php
//extract data from the post
// extract($_GET);
$uid = $_GET['uid'];
$phone = $_GET['phone'];
$pwd = $_GET['pwd'];
$msg = $_GET['msg'];
$provider = 'way2sms';
//set POST variables
$fields = array(
'uid'=>rawurlencode($uid),
'phone'=>rawurlencode($phone),
'pwd'=>rawurlencode($pwd),
'msg'=>rawurlencode($msg),
'provider'=>rawurlencode($provider)
);
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
///curl part(please help)
?>
这里是一个基本的cURL POST脚本。它没有错误处理-您绝对应该这样做
post字符串应该是这样的:ubaid.tk/sms/sms.aspx?uid=9746674889&pwd=passwod&phone=9746674889&msg=hjgyjgKJKJK&provider=way2sms&send=send=send整个内容是GET,而不是post。警告:curl\u setopt()在/home/funzonem/public\html/service/api/sms.php第20行的参数计数错误警告:curl\u setopt()的参数计数错误在第21行的/home/funzonem/public_html/service/api/sms.php中。我收到了这个错误代码正在运行,但仍然无法发布。posted表示输出应为1。如果我尝试将url直接提供给它发布的浏览器。这是正确的url,在这种情况下,您想要的是获取,而不是发布。你应该仔细阅读它们是如何工作的,这样你就知道你在处理什么了。请参阅上面的编辑。我的主机不支持文件内容。你能提供能得到这个url的curl代码吗?@sabin14我编辑的第一个代码应该可以。上面有三个版本,使用中间的一个。
<?php
// Destination URL
$url = 'http://ubaid.tk/sms/sms.aspx';
// Raw data to send
$fields = array(
'uid' => $_GET['uid'],
'phone'=>$_GET['phone'],
'pwd'=>$_GET['pwd'],
'msg'=>$_GET['msg'],
'provider'=>'way2sms'
);
// Build $fields into an encoded string
$body = http_build_query($fields);
// Initialise cURL
$ch = curl_init($url);
// Set options (post request, return body from exec)
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
// Do the request
$result = curl_exec($ch);
// Echo the result
echo $result;
<?php
// Destination URL
$url = 'http://ubaid.tk/sms/sms.aspx';
// Raw data to send
$fields = array(
'uid' => $_GET['uid'],
'phone'=>$_GET['phone'],
'pwd'=>$_GET['pwd'],
'msg'=>$_GET['msg'],
'provider'=>'way2sms'
);
// Build $fields into an encoded string and append to URL
$url .= '?'.http_build_query($fields);
// Initialise cURL
$ch = curl_init($url);
// Set options (post request, return body from exec)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
// Do the request
$result = curl_exec($ch);
// Echo the result
echo $result;
<?php
// Destination URL
$url = 'http://ubaid.tk/sms/sms.aspx';
// Raw data to send
$fields = array(
'uid' => $_GET['uid'],
'phone'=>$_GET['phone'],
'pwd'=>$_GET['pwd'],
'msg'=>$_GET['msg'],
'provider'=>'way2sms'
);
// Build $fields into an encoded string and append to URL
$url .= '?'.http_build_query($fields);
// Do the request
$result = file_get_contents($url);
// Echo the result
echo $result;