views:

403

answers:

3

How can I sanitize URLs made from strings to replace characters like space to %20 and etc?

How can I Print a NSURL in NSLog?

How can I send data to a webserver using POST? i know that for HTML GET:

NSURL * theURL = [[NSURL alloc] initWithString:url];
NSString * results = [NSString stringWithContentsOfURL:theURL];

will do the deal, but what is i am sending over secret data such as username and password?

+2  A: 

First off, multiple questions should be asked as multiple questions, but I'll answer anyway:

  1. NSString *escapedString = [string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  2. NSLog(@"URL is: %@, contents is: %@", myURLObject, [NSString stringWithContentsOfURL:myURLObject]);
  3. Sending POST data has already been answered in this question
rpetrich
Also, if you aren't releasing theURL later on, it will be leaked.
rpetrich
+1  A: 

The questions changed while I was writing my answer..This is answering how to POST.

You will need to use NSURLConnection.

Jab
+1  A: 

An easier framework for running POST requests is Ben Copsey's ASIHTTPRequest kit, which wraps around NSHTTPRequest and adds a lot of useful functionality. It will save you time and it is definitely worth checking out.

Alex Reynolds