Jump to content
Welcome to InsanelyMac Forum

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customize your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more! This message will be removed once you have signed in.

Sign in to follow this  

[newbie sorry]- ios http post help

2 posts in this topic

Recommended Posts

Hello, I was hoping someone could point me in the correct direction. I've been having huge troubles getting my ios app (xcode 5 ios7 sdk) communicating with my php. It is only a signup form being posted to a php to then be stored on a mysql(so nothing special).


I have sucessfully completed my Android app and am hoping to rewrite it for ios yet I've spent the last 5 days failing to get past the http post issue :(


I feel like I've followed every tutorial than google indexes to no avail.


Now in my Android app I've used the basicnamevaluepairs to create an array to be sent.




  // Building Parameters
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("firstname", firstname));
            params.add(new BasicNameValuePair("surname", surname));
            params.add(new BasicNameValuePair("hometown", hometown));
            params.add(new BasicNameValuePair("phone", phone));
            params.add(new BasicNameValuePair("email", email));
            params.add(new BasicNameValuePair("deviceid", android_id));
            params.add(new BasicNameValuePair("phonetype", phonetype));
            params.add(new BasicNameValuePair("yob", yob));
            params.add(new BasicNameValuePair("regId", regId));
            params.add(new BasicNameValuePair("gender", gender));
            // getting JSON Object
            // Note that create product url accepts POST method
            JSONObject json2 = jsonParser.makeHttpRequest(url_sign_up,
                    "POST", params);
            Log.d("params", params.toString());

Which posts this and recieves a reply from a php that just prints the input as reply;


[firstname=ovuy, surname=ouvy, hometown=uyv, phone=898, email=ouvy, deviceid=469524fe14b1e09d, phonetype=Android, yob=7654, regId=APA91bERNRY-2gi205zeMsjzTx9gpKQUmdncR7C1iSQr0t7FnKQqNFt8-gBpbhKebHeBtETu45vqvjgFPUbO2sCKqtjXjvF2aH9seD8wLyQtwiA2VDJFX0Kcb2YZOllD_NoL5tFcGmPYV4QZDBd0hGJpI1OVVs_S9huuFCqHgBdCMBGRSCnLXGg, gender=Male]

and in response;




[CONTENT_TYPE] => application/x-www-form-urlencoded


[REMOTE_PORT] =>50281

Now when I do it in ios I send exactly the same array (string) but I have a few things returned that are different;





[HTTP_ACCEPT] => */*

[HTTP_ACCEPT_ENCODING] => gzipp, deflate

[HTTP_USER_AGENT] => *appname*/1.0 CFNETWORK/609.1.4 Darwin/12.5.0

[REMOTE_PORT] => 50337



- (IBAction)SignUp:(id)sender {


    NSString *post = [[NSString alloc] initWithFormat:@"[firstname=%@, surname=%@, yob=%@, gender=%@, hometown=%@, phone=%@, email=%@, deviceid=%@, regId=%@, phonetype=%@]",[_FirstName text],[_Surname text],[_YOB text],[_Gender text],[_HomeTown text],[_PhoneNO text],[_Email text],[_deviceid text],[_regID text],[_phonetype text]];

    NSLog(@"PostData: %@",post);


    NSURL *url=[NSURL URLWithString:@"http://mynightapp.co.uk/iostest.php"];


    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding];


    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];


    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];

    [request setURL:url];

    [request setHTTPMethod:@"POST"];

    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];

    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];

    [request setHTTPBody:postData];


    NSError *error = [[NSError alloc] init];

    NSHTTPURLResponse *response = nil;

    NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];


    NSLog(@"Response code:%d", [response statusCode]);

    if ([response statusCode] >=200 && [response statusCode] <300)


        NSString *responseData = [[NSString alloc] initWithData:urlData encoding:NSUTF8StringEncoding];

        NSLog(@"Respinse ==> %@", responseData);


        SBJsonParser *jsonParser = [SBJsonParser new];

        NSDictionary *jsonData = (NSDictionary *) [jsonParser objectWithString:responseData error:nil];


        NSInteger sucess = [(NSNumber *) [jsonData objectForKey:@"sucess"] integerValue];


        if (sucess==1)


            NSLog(@"Signed up");

This gets declined each time saying params are not filled in yet nslog says they are.


Sorry for the wall of text. I am literally at my wits end :(


Is it an issue at server side with the [ACCEPT_ENCODING] =? gzip, deflate ?


other than the remote port being different I cannot see the issue (presume thats down to me using a vm whilst waiting for my hackingtosh bits to show up).


Any ideas?


I will worship anyone who can help me :D

EDIT: I should add I have also attempted using NSDictionary with obejectsandkeys to the same effect.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.