Link to home
Start Free TrialLog in
Avatar of FolkLore
FolkLoreFlag for South Africa

asked on

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
Avatar of Peter Hart
Peter Hart
Flag of United Kingdom of Great Britain and Northern Ireland image

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
Avatar of FolkLore

ASKER

Hi chilternPC,

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

Regards,

Kobus
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?
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.
https://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!
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
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.
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
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
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.
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

SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Thanks for the last answer, Ray. I will post your comments to the provider.

Regards,

Kobus
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
Thanks for the points -- I think you're on firm ground, ~Ray
$_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 -