Handling posted data from external source

Hi,

One of my service provides (SMS message) send me the text received via the SMS message by posting the data to my own service, where I need to process it.

Although they POST the data to me, there is only GET data available for me, as it obviously is retrieved from the query string. Printing out the $_POST[] variable results in an empty array, and the $_GET[] array has all the data that they send to me.

The provider says they get errors because I am dealing with the data as GET, and that I should change this to post. I am at a loss to implement what needs to be done here - or even if there *is* something that can be done.

My service provider's answer: "I’ve taken a look into this with our third line support team and it seems the problem relates to the POST nature of our handout and your platforms expectation of a GET handout. If I run a test using GET I get a HTTP 200 response from your platform but when testing the POST method I get a HTTP 500. Are you able to change your platform to expect the POST method? "

What do I do to get this problem working?

Kind regards,

Kobus
FolkLoreAsked:
Who is Participating?
 
Ray PaseurConnect With a Mentor Commented:
$_REQUEST will contain GET, POST and COOKIE information according to the order of the request vars.
http://php.net/manual/en/reserved.variables.request.php
http://php.net/manual/en/ini.core.php#ini.request-order

Executive summary: There is nothing wrong with your code.  The remote service is inaccurate in telling you they are making a POST request.  If you use $_REQUEST and they ever change to POST, your script will still work.  However be aware of the nature of associative arrays - identically named indexes will cause the data to be overwritten.  So avoid setting a cookie with a name that might collide with something you expect to receive in GET or POST requests.
0
 
Peter HartCommented:
do you mean you have to provide a post service to them?
check out
http://www.lornajane.net/posts/2010/three-ways-to-make-a-post-request-from-php
0
 
FolkLoreAuthor Commented:
Hi chilternPC,

No, they make a POST to me. I am receiving the data from them.

Regards,

Kobus
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
Julian HansenCommented:
How were the tests described by your ISP conducted?

Who is your ISP?

What code are you using to get the Posted data?

Have you dumped the $HTTP_RAW_POST_DATA value to see what is in there?
0
 
Ray PaseurCommented:
GET and POST are terms of art - they are descriptors of the HTTP Client-Server request method.  This article tells a little more about it.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/A_11271-Understanding-Client-Server-Protocols-and-Web-Applications.html

In a nutshell, GET requests are information-only.  POST requests can change the data on the server.

You may want to consider using $_REQUEST, however it would be better to understand why a remote service would be telling you there was a POST request, but sending it in the form of a GET!
0
 
FolkLoreAuthor Commented:
Hi julianH,

Here is my code:

        if (isset($_GET['X-E3-Account-Name']))
        {
            ini_set('display_errors', 1);
            $_GET['X-E3-Hex-Message'] = hex2bin($_GET['X-E3-Hex-Message']);
            $data = serialize($_GET);
            $db = new PDO('mysql:host=localhost;dbname=dbnamehere;charset=utf8', 'dbuserhere', 'dbpasshere');
            $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
            $stmt = $db->prepare("INSERT INTO `inbound_data` (`id`, `data`, `createdate`, `moddate`) VALUES ('', ?, NOW(), NOW())");
            $stmt->execute(array($data));
            header("HTTP/1.1 200 OK", true, 200);
            echo 'Success: HTTP status 200 sent.<br />';
            echo 'The message saved to database is: ' . $data;
            exit();
        }

Open in new window


The data is posted to me, but there is nothing in php://input (raw posted data) and there is nothing in $_POST[]. All data is in $_GET[] and $_REQUEST[].

The ISP is Dialogue Communications - a mobile short message provider with offices in UK, US , South Africa, Australia and Singapore that I know of.

I am not sure what your first question means. I can tell you the following:

1. I send an SMS to a number, e.g., I send "testing" to number 12345.
2. My service provider for the SMS messages receives it, and POST it to my web system
3. My system receives the data and reacts (e.g., sends the SMS sender a code)

I hope this answers your questions?

Regards,

Kobus
0
 
Ray PaseurCommented:
It sounds like there is nothing wrong on your end -- the service is telling you they are sending a POST request, but in reality they are sending you a GET request.

If you want the best SMS service available consider Twilio.
0
 
FolkLoreAuthor Commented:
Hi Ray,

Thanks - I have changed $_GET to $_REQUEST in my code snippet above, but I am not sure how this will make a difference, but I will just about try anything now :-) How I process the information should not be relevant to my provider, should it?

They say they do a POST, but when I retrieve it via the query string, it is certainly a GET for me? Or is there some header or something I have to send that will change how it is received? I am lost :-(

Regards,

Kobus
0
 
FolkLoreAuthor Commented:
Hi Ray,

Just to make troubleshooting easier:

From their logs they get errors, but when I paste the URL from their logs to my browser's address bar, I do not get any errors, and the data is submitted correctly. Does that tell you anything?

Regards,

Kobus
0
 
Ray PaseurCommented:
How I process the information should not be relevant to my provider, should it?
I am fairly sure that is correct.  It sounds like they speak to you with a RESTful request made via the GET method.

Try this... use var_dump() to print out the contents of $_GET, $_POST and $_REQUEST.  See if the output makes sense.
0
 
FolkLoreAuthor Commented:
Here is what var_dump() outputs:

First is  var_dump($_REQUEST);, then var_dump($_POST); and finally var_dump($_GET);

I realized that I am GETTING the information from the query string, hence in my code I used $_GET, although now changed to $_REQUEST on your recommendation.

array(12) {
  ["X-E3-Account-Name"]=>
  string(10) "imp*******"
  ... 
  ["X-E3-Timestamp"]=>
  string(25) "2013-06-1720:40:13.000000"
}
array(0) {
}
array(12) {
  ["X-E3-Account-Name"]=>
  string(10) "imp*******"
  ... 
  ["X-E3-Timestamp"]=>
  string(25) "2013-06-1720:40:13.000000"
}

Open in new window

0
 
Chris StanyonConnect With a Mentor Commented:
FYI - $_REQUEST is an array that contains all the data from $_POST, $_GET and $_COOKIE.

The above dump tells me the data is definitely coming in via GET (which you'll see in $_REQUEST and $_GET). If the info is being passed via a Query String, then it is a GET request.

It appears that your provider is passing you duff info - they are clearly sending data via GET!!
0
 
FolkLoreAuthor Commented:
Sorry for the many comments, but Ray, could you please clarify this part of one of your responses for me?

"...however it would be better to understand why a remote service would be telling you there was a POST request, but sending it in the form of a GET!"

Did you mean I need to do something here? Or is this information I need to provide to my provider?

Regards,

Kobus
0
 
FolkLoreAuthor Commented:
Hi Chris,

Thanks - I appreciate your feedback. It is definitely in line with what Ray is sending as well. That is why the provider's statement confused me so - the data comes from the query string, so it is GET.

Now back to the waiting...

Regards,

Kobus

PS: Due to the amount of to and fro here, I will up the points a bit.
0
 
FolkLoreAuthor Commented:
Thanks for the last answer, Ray. I will post your comments to the provider.

Regards,

Kobus
0
 
FolkLoreAuthor Commented:
Thanks guys, I am laying this to rest. Nothing more you guys can do if the provider needs to fix something on their side.

Kind regards,

Kobus
0
 
Ray PaseurCommented:
Thanks for the points -- I think you're on firm ground, ~Ray
0
 
Julian HansenCommented:
$_REQUEST just means get from either POST or GET - it is a combination of the two. So if your info is coming in via a GET then it will be in both GET and REQUEST but likewise if it comes in a via POST it will be in POST and REQUEST (but not get).

So in this context you are doing the same as accessing the GET array.

My first question related to the response from your SP where they say they tested your script and received an HTTP 200 on the GET and and 500 on the POST - I was asking what they were doing to test that - did you give them a test script or were they accessing your live script - would it be something we could have access to. It seems odd they are getting a HTTP 500 when posting to your site - the script should be accessible irrespective of the means by which data is passed to the script.

Also -
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.