Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

rup28aug

macrumors newbie
Original poster
Oct 22, 2008
12
0
hi all,
i am new to iPhone programming.
i want to access some function(REST) on the server. i have no idea that how can i request to this server function and get response?

i want to simple code where i can supply server address and function name. Please suggest very simple way for doing this task(since i am on learning stage and very little knowledge)
 

detz

macrumors 65816
Jun 29, 2007
1,051
0
This is about as simple as I can make it.
PHP:
NSString *urlString = [NSString stringWithFormat:@"http://google.com"];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"GET"];
	
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *results = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
 

rup28aug

macrumors newbie
Original poster
Oct 22, 2008
12
0
sir ,
thanks for your reply.
i want to like to use POST method . so can you provide some snippet related to post method
 

rup28aug

macrumors newbie
Original poster
Oct 22, 2008
12
0
sir,
thanks for your reply.
actually i want to call a method which take parameter and return result in XML format. so how can i set method and parameter in POST method?
 

Pring

macrumors 6502
Sep 17, 2003
310
0
I wept when reading this...

rup28aug, as an exercise perhaps you can explain what GET and POST actually mean? I think you should do some research before posting your questions.
 

detz

macrumors 65816
Jun 29, 2007
1,051
0
Well if you want to actually POST data and not just do a GET with a post method it's more complicated. Do a search, there are articles written on it, my code is to messy to post examples. :p
 

sujithkrishnan

macrumors 6502
May 9, 2008
265
0
Bangalore
hi all,
i am new to iPhone programming.
i want to access some function(REST) on the server. i have no idea that how can i request to this server function and get response?

i want to simple code where i can supply server address and function name. Please suggest very simple way for doing this task(since i am on learning stage and very little knowledge)

[request setHTTPBody:<whatever u want to send as post (NSData type)>];
[request setHTTPMethod: @"POST"];
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.