Jump to content

[newbie sorry]- ios http post help


  • Please log in to reply
1 reply to this topic

#1
Sandman

Sandman

    InsanelyMac Protégé

  • Members
  • Pip
  • 1 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.

 

Java

 

  // 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;

Array

(

[HTTP_CONNECTION] => Keep-Alive

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

[CONTENT_LENGTH] => 316

[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;

 

 

ARRAY

(

[HTTP_ACCEPT] => */*

[HTTP_ACCEPT_ENCODING] => gzipp, deflate

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

[REMOTE_PORT] => 50337

XCODE CODE

 

- (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];

        NSLog(@"%@",jsonData);

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

        NSLog(@"%d",sucess);

        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.



#2
TH3L4UGH1NGM4N

TH3L4UGH1NGM4N

    (~_~)

  • News Team
  • 1,154 posts
  • Gender:Male
  • Location:Wonderland
  • Interests:(~_^)

What is the response data that the server is giving back when the

responseData
object is being returned?





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

© 2014 InsanelyMac  |   News  |   Forum  |   Downloads  |   OSx86 Wiki  |   Mac Netbook  |   PHP hosting by CatN  |   Designed by Ed Gain  |   Logo by irfan  |   Privacy Policy