Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Dec 17, 2008, 04:32 AM   #1
rup28aug
macrumors newbie
 
Join Date: Oct 2008
Http request and response

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)
rup28aug is offline   0 Reply With Quote
Old Dec 17, 2008, 06:42 AM   #2
detz
macrumors 65816
 
Join Date: Jun 2007
This is about as simple as I can make it.
PHP Code:
NSString *urlString = [NSString stringWithFormat:@"http://google.com"];
NSMutableURLRequest *request = [[[NSMutableURLRequest allocinitautorelease];
[
request setURL:[NSURL URLWithString:urlString]];
[
request setHTTPMethod:@"GET"];
    
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *results = [[NSString allocinitWithData:returnData encoding:NSUTF8StringEncoding]; 
detz is offline   0 Reply With Quote
Old Dec 17, 2008, 08:07 AM   #3
rup28aug
Thread Starter
macrumors newbie
 
Join Date: Oct 2008
sir ,
thanks for your reply.
i want to like to use POST method . so can you provide some snippet related to post method
rup28aug is offline   0 Reply With Quote
Old Dec 17, 2008, 09:51 AM   #4
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Quote:
Originally Posted by rup28aug View Post
sir ,
thanks for your reply.
i want to like to use POST method . so can you provide some snippet related to post method
Umm... maybe try
Code:
[request setHTTPMethod:@"POST"];
dejo is online now   0 Reply With Quote
Old Dec 17, 2008, 09:06 PM   #5
x11joex11
macrumors newbie
 
Join Date: Dec 2008
Quote:
Originally Posted by dejo View Post
Umm... maybe try
Code:
[request setHTTPMethod:@"POST"];
I LOL'ed at your response, hehe. Especially after seeing 'GET' in his code. Sometimes the answer is right in front of our noses
x11joex11 is offline   0 Reply With Quote
Old Dec 18, 2008, 12:20 AM   #6
rup28aug
Thread Starter
macrumors newbie
 
Join Date: Oct 2008
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?
rup28aug is offline   0 Reply With Quote
Old Dec 18, 2008, 04:17 AM   #7
Pring
macrumors 6502
 
Join Date: Sep 2003
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.
__________________
Dardan Software
Neil Inglis' Blog
Check out Escape Pod and Alphonetic on iTunes!
Pring is offline   0 Reply With Quote
Old Dec 18, 2008, 04:19 AM   #8
detz
macrumors 65816
 
Join Date: Jun 2007
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.
detz is offline   0 Reply With Quote
Old Dec 18, 2008, 09:46 AM   #9
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Quote:
Originally Posted by rup28aug View Post
so how can i set method and parameter in POST method?
The "method" and parameters can be put into the request URL. For example, @"http://www.google.com/search?hl=en&q=iphone&btnG=Google+Search&aq=f&oq="
dejo is online now   0 Reply With Quote
Old Dec 22, 2008, 03:41 AM   #10
sujithkrishnan
macrumors 6502
 
Join Date: May 2008
Location: Bangalore
Send a message via Yahoo to sujithkrishnan
Quote:
Originally Posted by rup28aug View Post
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"];
sujithkrishnan is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Forum Jump

All times are GMT -5. The time now is 11:19 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC