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 5850137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T13:05:56+00:00 2026-05-22T13:05:56+00:00

I have Objective C code creating an NSUrlConnection as follows: //prepar request NSString *urlString

  • 0

I have Objective C code creating an NSUrlConnection as follows:

//prepar request
    NSString *urlString = [NSString stringWithFormat:@"http://ctruman.info/post.php"];
    NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
    [request setURL:[NSURL URLWithString:urlString]];
    [request setHTTPMethod:@"POST"];

    //set headers
    NSString *contentType = [NSString stringWithFormat:@"text/xml"];
    [request addValue:contentType forHTTPHeaderField: @"Content-Type"];

    //create the body
    NSString *formData = [[NSString alloc] initWithFormat:@"%@  %@", username.text, password.text];

    NSData *postData = [[NSString stringWithString:formData] dataUsingEncoding:NSUTF8StringEncoding];

    //post
    [request setHTTPBody:postData];

    //get response
    NSHTTPURLResponse* urlResponse = nil;  
    NSError *error = [[NSError alloc] init];  
    NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];  
    NSString *result = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
    NSLog(@"Response Code: %d", [urlResponse statusCode]);
    if ([urlResponse statusCode] >= 200 && [urlResponse statusCode] < 300) {
        NSLog(@"Response: %@", result);
     }  

Then I have a php script that is supposed to read my POST variables that are being sent:

<?php
print('<pre>');
print_r($_POST);
print('</pre>');
?>

When I execute this, NSLog spits out the following:

Array
    (
    )

Why is it not printing out my post variables? Am I making the POST request incorrectly?

  • 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-05-22T13:05:56+00:00Added an answer on May 22, 2026 at 1:05 pm

    As it looks to me, PHP is trying to read your POST submission as if it were a properly formatted PHP POST payload. Instead, you’re setting the content-type to XML content — which probably confuses the heck out of PHP. It’s looking for encoded variables, and finding XML.

    You’ve got 2 options:

    1. Read in the XML and parse it yourself using PHP:
      $xml = file_get_contents(‘php://input’);
      an example for reading input is here: http://www.codediesel.com/php/reading-raw-post-data-in-php/
      then you can parse it with PHP’s xml support: http://us.php.net/xml

    2. Recode your objective-C to just send normal POST parameters up to the server. I use the ASIHTTPRequest libraries and it’s easy. http://allseeing-i.com/ASIHTTPRequest/

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

Sidebar

Related Questions

I have a somewhat messily-formatted Objective-C code base. Is there a way to have
Say I have the following Objective-C class: @interface Foo { int someNumber; NSString *someString;
I have a simple question about creating multiple initialisers within an objective-c class. Basically
I have an enum in my objective-C code similar to this: typedef enum {
I have some Objective-C code that does the job for me. But is it
Do I really have to learn Objective-C to develop solid Mac Apps? As Mac
I'm learning objective-C and Cocoa and have come across this statement: The Cocoa frameworks
We have a collection of commercial MFC/C++ applications which we sell using Stingray Objective
I'm just beginning to have a look at Objective-C and Cocoa with a view
Will a MacBook Air have enough horsepower for occasional development in Ruby? Objective C?

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.