Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7852473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:25:35+00:00 2026-06-02T19:25:35+00:00

I’m doing a project on an iPhone. Here I have to send a POST

  • 0

I’m doing a project on an iPhone. Here I have to send a POST request to a web service. I use a NSMutableURLRequest and a NSURLConnection to send the data, and the server uses PHP. I have found that the check if ($_SERVER['REQUEST_METHOD'] != "POST") always fails, as in returns ‘GET’, even when I try it on localhost.

My POST request looks as follows (sniffed via Wireshark):

POST tester.php HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:10.0.2) Gecko/20100101 Firefox/10.0.2
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Referer: http://localhost/tester.php
Content-Type: application/x-www-form-urlencoded
Content-Length: 422

protocol=4&msgtype=authorize&merchant=86189919&language=da&ordernumber=1274168351&amount=100&currency=DKK&continueurl=http%3A%2F%2Fquickpay.net%2Ffeatures%2Fpayment-window%2Fok.php&cancelurl=http%3A%2F%2Fquickpay.net%2Ffeatures%2Fpayment-window%2Ferror.php&callbackurl=http%3A%2F%2Fquickpay.net%2Ffeatures%2Fpayment-window%2Fcallback.php&autocapture=0&cardtypelock=&splitpayment=1&md5check=d2259d9db077e0f5a41b4bf271c3c549

Of course there is a lot dummy text in there, that would normally not be there from a iPhone, but I have tried to make the same call via a html form, and that worked. Therefore I have copied all the information over to see if that would make a difference, but to no avail.

I have compared the two requests (one from the iPhone, the other from my php page) and they look exactly the same.

I’m flabbergasted – does anyone have a good advice on what to do?

Edit:

Your test isn’t testing for post or post vs get, it is testing for POST specifically, you could have a case issue there… Have you tried inspecting the request itself in php? – Grady Player

Yes, that could be true, but the line always returns GET, so the case issue is covered, if that’s what you mean.

Also, please post the result of print_r($_SERVER) from the server when the iPhone sends the request – Aleks G

Array( HTTP_HOST => 10.11.105.254 HTTP_USER_AGENT => Mozilla/5.0 (iPhone Simulator; CPU iPhone OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9B176 HTTP_ACCEPT => text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8 HTTP_ACCEPT_LANGUAGE => en-us HTTP_ACCEPT_ENCODING => gzip, deflate HTTP_CONNECTION => keep-alive PATH => /usr/bin:/bin:/usr/sbin:/sbin SERVER_SIGNATURE => Apache/2.2.21 (Unix) DAV/2 PHP/5.3.8 with Suhosin-Patch Server at 10.11.105.254 Port 80
SERVER_SOFTWARE => Apache/2.2.21 (Unix) DAV/2 PHP/5.3.8 with Suhosin-Patch SERVER_NAME => 10.11.105.254 SERVER_ADDR => 10.11.105.254 SERVER_PORT => 80 REMOTE_ADDR => 10.11.105.254 DOCUMENT_ROOT => /Library/WebServer/Documents SERVER_ADMIN => you@example.com SCRIPT_FILENAME => /Users/tester.php REMOTE_PORT => 51492 GATEWAY_INTERFACE => CGI/1.1 SERVER_PROTOCOL => HTTP/1.1 REQUEST_METHOD => GET QUERY_STRING => REQUEST_URI => /tester.php SCRIPT_NAME => /tester.php PHP_SELF => /tester.php REQUEST_TIME => 1334211212 argv => Array argc => 0 )

Did you try checking to see if a known variable, e.g. $_POST[‘known_to_be_set_by_client’] is set or not? It’s not PHP that figures out if a request is POST or GET, it’s the web server. – Tim Post

When I try to echo a known variable from the iPhone request, it is of course empty. Which makes sense. When I echo the same thing from the form it is there.

Post the iOS code your using to make the actual request. – Cliff Ribaudo

Here is the code that creates the request and sends it:

//variables
NSString *protocol = @"4";
NSString *msgtype = @"authorize";
NSString *merchant = @"86189919";
NSString *language = @"da";
NSString *orderNo = @"1274168351";
NSString *amount = @"100";
NSString *currency = @"DKK";
NSString *continueURL = @"http://quickpay.net/features/payment-window/ok.php";
NSString *cancelURL = @"http://quickpay.net/features/payment-window/error.php";
NSString *callbackURL = @"http://quickpay.net/features/payment-window/callback.php";
NSString *autoCapture = @"0";
NSString *cardtypeLock =@"";
NSString *splitText = @"1";
NSString *md5check = @"d2259d9db077e0f5a41b4bf271c3c549";

//setting up the request
NSMutableString *post = [[NSMutableString alloc] initWithString:@"protocol="];
[post appendString:protocol];

[post appendString:@"&msgtype="];
[post appendString:msgtype];

[post appendString:@"&merchant="];
[post appendString:merchant];

[post appendString:@"&language="];
[post appendString:language];

[post appendString:@"&ordernumber="];
[post appendString:orderNo];

[post appendString:@"&amount="];
[post appendString:amount];

[post appendString:@"&currency="];
[post appendString:currency];

[post appendString:@"&continueurl="];
[post appendString:continueURL];

[post appendString:@"&cancelurl="];
[post appendString:cancelURL];

[post appendString:@"&callbackurl="];
[post appendString:callbackURL];

[post appendString:@"&autocapture="];
[post appendString:autoCapture];

[post appendString:@"&cardtypelock="];
[post appendString:cardtypeLock];

[post appendString:@"&splitpayment="];
[post appendString:splitText];

[post appendString:@"&md5check="];
[post appendString:md5check];


//escape characters
NSString *tmp = (__bridge NSString *)CFURLCreateStringByAddingPercentEscapes(
                                        NULL, 
                                        (__bridge CFStringRef)post, 
                                        NULL, 
                                        (CFStringRef)@";/:@+$,~", 
                                        kCFStringEncodingUTF8
                                        );


NSData *body = [tmp dataUsingEncoding:NSUTF8StringEncoding];
//setup url
NSString *urlString =@"http://10.10.225.255/tester.php";
NSURL *quickUrl = [NSURL URLWithString:urlString];

//setup URL request
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]init];
//method
[request setHTTPMethod:@"POST"];
//url
[request setURL:url];

//body data to string
NSString *strData = [[NSString alloc]initWithData:body encoding:NSUTF8StringEncoding];

//content length
NSString *postLenght = [NSString stringWithFormat:@"%d", [body length]];

//set body
[request setHTTPBody:body];

//Dummy data to make the request look like the same from the HTML form.
[request setValue:@"localhost" forHTTPHeaderField:@"Host"];
[request setValue:@"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:10.0.2) Gecko/20100101 Firefox/10.0.2" forHTTPHeaderField:@"User-Agent"];
[request setValue:@"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" forHTTPHeaderField:@"Accept"];
[request setValue:@"en-us,en;q=0.5" forHTTPHeaderField:@"Accept-Language"];
[request setValue:@"gzip, deflate" forHTTPHeaderField:@"Accept-Encoding"];
[request setValue:@"http://localhost/tester.php" forHTTPHeaderField:@"Referer"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
[request setValue:postLenght forHTTPHeaderField:@"content-length"];

//send the request to server
if([[NSURLConnection alloc] initWithRequest:request delegate:self]){
    NSLog(@"sending data to quickpay"); 
} 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T19:25:37+00:00Added an answer on June 2, 2026 at 7:25 pm

    I figured it out.
    As expected, it was an oversight by myself!
    When I loaded to url into the UIWebView, in the delegate, I used the loadRequest method, which of course uses a GET request to return the content. Instead I should have used the loadHTMLString:baseURL: method instead to load the returned data.
    This error meant that the app issued another GET request after my initial POST, which caused the error. Obviously I didn’t notice this extra request for a looong time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I am doing a simple coin flipping experiment for class that involves flipping a
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.