繁体   English   中英

Php Curl发布到.aspx

[英]Php Curl Posting to .aspx

我没有在php中使用curl发布到网址: http//example.com/sms/sms.aspx

帖子字符串应该是以下模式:example.com/sms/sms.aspx?uid = 9746674889&pwd = passwod&phone = 9746674889&msg = hjgyjgKJKJK&provider = way2sms&send = SEND

如果它被发布,则输出将为1,否则为-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脚本。 它没有错误处理 - 你一定要阅读cURL手册

<?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;

编辑

因为你真正想要的是GET而不是POST,代码变得更加简单:

<?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;

......或者这整件事可以在没有cURL的情况下完成:

<?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;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM