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 Apr 21, 2009, 03:48 PM   #1
iPhoneeeee
macrumors newbie
 
Join Date: Apr 2009
NSURLConnection - Using POST

I have searched, searched and searched without any success, so I am making my first post here. Please be kind and offer some guidance.

I am looking for example or documentation with discussion on using POST, specifically on topic of sending data to PHP forms and website.

Please help.

Thank you
iPhoneeeee is offline   0 Reply With Quote
Old Apr 22, 2009, 12:33 AM   #2
xinevil
macrumors newbie
 
Join Date: Jul 2008
Quote:
Originally Posted by iPhoneeeee View Post
I have searched, searched and searched without any success, so I am making my first post here. Please be kind and offer some guidance.

I am looking for example or documentation with discussion on using POST, specifically on topic of sending data to PHP forms and website.

Please help.

Thank you
You can do it this way:
PHP Code:
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.example.org/file.php"]
                                                           
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
                                                       timeoutInterval
:60.0];
    [
request setHTTPMethod:@"POST"];
    [
request setHTTPBody:[[NSString stringWithFormat:@"value1=%@&value2=%@",
                           [
sessionId URLEncodeString],
                           [[
UIDevice currentDeviceuniqueIdentifier]] dataUsingEncoding:NSUTF8StringEncoding]];
    [[
UIApplication sharedApplicationsetNetworkActivityIndicatorVisible:YES];
    
NSURLConnection *connection = [[NSURLConnection allocinitWithRequest:request delegate:self];
    if (
connection) {
        
receivedData = [[NSMutableData dataretain];
    }
    [
tableView reloadData]; 
The URLEncodeString.h:
PHP Code:
//
//  URLEncode.h
//
//  Created by Nicky Gerritsen on 24-03-09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>


@interface NSString (URLEncode)
+ (
NSString *)URLEncodeString:(NSString *)string;
- (
NSString *)URLEncodeString;
@
end 
And URLEncodeString.m:
PHP Code:
//
//  URLEncode.m
//
//  Created by Nicky Gerritsen on 24-03-09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "URLEncode.h"


@implementation NSString (URLEncode)

// URL encode a string
+ (NSString *)URLEncodeString:(NSString *)string {
    
NSString *result = (NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)stringNULLCFSTR("% '\"?=&+<>;:-"), kCFStringEncodingUTF8);
    
    return [
result autorelease];
}

// Helper function
- (NSString *)URLEncodeString {
    return [
NSString URLEncodeString:self];
}

@
end 
Hope this helps
xinevil is offline   0 Reply With Quote
Old Apr 22, 2009, 02:11 PM   #3
iPhoneeeee
Thread Starter
macrumors newbie
 
Join Date: Apr 2009
Thank you very much!
iPhoneeeee 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

Similar Threads
thread Thread Starter Forum Replies Last Post
Resolved: AFNetworking Vs NSURLConnection ? Tander iPhone/iPad Programming 3 Jul 30, 2013 04:36 AM
Error handling in NSURLConnection sendAsynchronousRequest waterskier2007 iPhone/iPad Programming 1 Mar 1, 2013 08:57 AM
Uploading file using NSURLConnection mycompuser Mac Programming 4 Nov 27, 2012 07:10 AM

Forum Jump

All times are GMT -5. The time now is 09:00 AM.

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

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