0

I'd like to pass an object such as this (JavaScript example)

var auth = new Object();
auth.method = "authenticateUser";
auth.data = new Object();
auth.data.email = "user11111@test.com";
auth.data.password = "123123";

to a php script when I'm making a post.

So far, I can only pass individual variables by appending to the url, but I'd like to be able to pass nested objects - such as in javascript examples above

NSString *post =[NSString stringWithFormat:@"username=%@&password=%@",usernameField.text, passwordField.text];
NSString *hostStr = @"{ANY URL}";
hostStr = [hostStr stringByAppendingString:post];
NSData *dataURL =  [NSData dataWithContentsOfURL: [ NSURL URLWithString: hostStr ]];    
NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSASCIIStringEncoding];
nuway
  • 2,324
  • 4
  • 27
  • 48

2 Answers2

0

Right now, you're using HTTP GET, which is hard to transmit complex data. What you can do is send an HTTP Post in iOS which uses the url and attaches the data inside a message body.

Community
  • 1
  • 1
HoratioCain
  • 915
  • 9
  • 19
0

Have you looked into AFNetworking? This makes it much easier to do what you are wanting. Almost every project I do involves a web-service of some kind, and a library like AFNetworking makes this process much easier. For one thing, you never want to pass a password along in a GET request, and you also want to make sure you are using a secure connection when passing credentials or sensitive data like that.

I have written a network class designed to work with AFNetworking. Here is an SO post that details the class.

Community
  • 1
  • 1
LJ Wilson
  • 14,445
  • 5
  • 38
  • 62