2012-01-08 5 views
0

Я не в состоянии отправлять с помощью завиток в PHP для URL: http://example.com/sms/sms.aspxPhp Curl Проводка для .aspx

Сообщение строка должна быть в шаблоне:? Example.com/sms/sms.aspx UID = 9746674889 & PWD = passwod & телефон = 9746674889 & тзд = hjgyjgKJKJK & провайдер = way2sms & посыла = 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) 

?> 
+1

Почтовая строка должна быть в форме: ubaid.tk/sms/sms.asp x? uid = 9746674889 & pwd = passwod & phone = 9746674889 & msg = hjgyjgKJKJK & provider = way2sms & send = SEND <- Thats GET – TimWolla

+0

Все это GET, а не POST. –

ответ

2

Вот базовый сценарий cURL POST. У него нет обработки ошибок - вы должны обязательно read the cURL manual.

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

EDIT

Так что вы на самом деле хотите, 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 as:

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

Предупреждение: неправильный параметр count для curl_setopt() в /home/funzonem/public_html/service/api/sms.php в строке 20 Предупреждение: Неверный параметр для curl_setopt() в/home/funzonem/public_html/service/api /sms.php в строке 21. Я получаю эту ошибку –

+0

@ sabin14 Извините, исправлено ... – DaveRandom

+0

Код работает. Но все равно он не может опубликовать. опубликовано означает, что результат должен быть 1. Если я попытаюсь дать url напрямую браузеру, он публикует сообщения. Это URL-адрес http://ubaid.tk/sms/sms.aspx?uid=9746674889&pwd=password&phone=9746674889&msg=hjgyjgKJKJK&provider=way2sms&send=SEND –

Смежные вопросы