开发者

cURL still Truncates Data...even with url encode

开发者 https://www.devze.com 2023-04-12 09:34 出处:网络
I am writing an sms application that retrieves the messages from a MYSQL database and uses cURL to pass the messagesto the smpp api of an sms gateway.I discovered a minor hitch with cURL...in the sens

I am writing an sms application that retrieves the messages from a MYSQL database and uses cURL to pass the messages to the smpp api of an sms gateway.I discovered a minor hitch with cURL...in the sense that the messages were being truncated.I got the application to add more data by using urlencode for the variable i was transferring...however some data was still being truncated.I was told it might be because of the length of the "GET" request..however i believe the only way to access the api of the sms gateway is via a "GET" request...based on what i was given..which is :

               http://xxx.yyy.zzz.qqq:8080/bulksms/bulksms?username=
               bbb&password=demo&type=0&dlr=Z&destination=806754367
               &source=TESTING&message=hi testing

The purpose of this application is to send academic reports of students to their guardians...so the request has to be lengthy.An average record taken from the table looks like this:

            The 开发者_Go百科Results For Your Son Pedro Have Been Released As Follows: 
           Mathematics:97% English Language:58% Crk:59% Social Studies:67% 
           Commerce:67% Government98% Biology: 100% Chemistry:78% Geography:99% 
           Religious Knowledge:Did Not Register
           Economics:54%

When i transferred the records for a test run with curl,this is what i got:

  The Results For Your Son Pedro Have Been Released As Follows:
   Mathematics:97% English Language:58% Crk:59% Social Studi

So my concern is to get the "COMPLETE" record and then send it to the sms gateway api.My revised code with the urlencode function is:

              <?php

            include 'sms_connect.php';
            $sql="select name from sms";
           $result=mysqli_query($link,$sql) or die("Error in sms".mysqli_error($link));
           while($row=mysqli_fetch_assoc($result))
            {$name=$row['name'];
            $url = "http://localhost/sms/index.php?name=".urlencode($name);
            $ch = curl_init();
             curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_HEADER, 0);

       // grab URL and pass it to the browser
         $results = curl_exec($ch);
         var_dump($results);

           }

     curl_close($ch);

          ?>

Ok...technical support person for the sms gateway said that with the smpp protocol..large amounts of data can be sent..i intend to experiment and abbreviate the data as appropriate. My index.php code is shown below:

    $name=$_GET['name'];
    include 'sms_connect.php';
    $sql="insert into sms_test values('$name')";
    $result=mysqli_query($link,$sql) 
     or die("Error in inserting name".mysqli_error($link));


Change

      $url = "http://localhost/sms/index.php?name=".$name;

To

      $url = "http://localhost/sms/index.php?name=".urlencode($name);

You can try with rawurlencode() as well

UPDATE Since now you get the data, but not the full, it seems that the problem is not in the curl anymore, but on the script you are sending the request to (localhost/sms/index.php). Keep in mind that SMS is limited in size, and that can be the reason the data is truncated. Anyway, without look at index.php, we cannot tell why you are not receiving the data.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号