Solved

Handling posted data from external source

Posted on 2013-06-24
18
313 Views
Last Modified: 2013-06-24
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
0
Comment
Question by:FolkLore
  • 9
  • 5
  • 2
  • +2
18 Comments
 
LVL 28

Expert Comment

by:chilternPC
ID: 39270917
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
 

Author Comment

by:FolkLore
ID: 39270930
Hi chilternPC,

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

Regards,

Kobus
0
 
LVL 51

Expert Comment

by:Julian Hansen
ID: 39271045
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
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39271076
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
 

Author Comment

by:FolkLore
ID: 39271098
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
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39271111
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
 

Author Comment

by:FolkLore
ID: 39271120
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
 

Author Comment

by:FolkLore
ID: 39271137
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
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39271153
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:FolkLore
ID: 39271175
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
 
LVL 42

Assisted Solution

by:Chris Stanyon
Chris Stanyon earned 50 total points
ID: 39271202
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
 

Author Comment

by:FolkLore
ID: 39271208
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
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 350 total points
ID: 39271213
$_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
 

Author Comment

by:FolkLore
ID: 39271217
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
 

Author Comment

by:FolkLore
ID: 39271223
Thanks for the last answer, Ray. I will post your comments to the provider.

Regards,

Kobus
0
 

Author Closing Comment

by:FolkLore
ID: 39271237
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
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39271248
Thanks for the points -- I think you're on firm ground, ~Ray
0
 
LVL 51

Expert Comment

by:Julian Hansen
ID: 39271257
$_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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
echo button 13 48
resizeing PHP image 2 24
url rewrites not working in codeigniter 2 13
How Can I Use otf Custom Font with TCPDF 7 15
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now