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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
NSURLConnection - didReceiveAuthenticationChallenge being called only once rinkedev iPhone/iPad Programming 0 Nov 4, 2011 10:15 AM
NSURLConnection for multiple views not receiving data asynchronously ashwinr87 iPhone/iPad Programming 13 Nov 3, 2011 05:47 PM
Purchase iPhone - Used/Unlocked - Canada - Input Requested VanMac iPhone 0 Dec 5, 2009 04:27 PM
use flash drive with xp - using virtual box 4now Windows, Linux & Others on the Mac 3 Sep 29, 2009 03:01 AM
Unix Using Hosting - Using application p71 Web Design and Development 6 Jan 29, 2007 10:05 PM


All times are GMT -5. The time now is 02:21 AM.

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

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