Shoaibi
Shoaibi

Reputation: 879

URLs and POST on the iPhone

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?

Upvotes: 0

Views: 1946

Answers (3)

Alex Reynolds
Alex Reynolds

Reputation: 96927

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.

Upvotes: 1

Jab
Jab

Reputation: 13775

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

You will need to use NSURLConnection.

Upvotes: 1

rpetrich
rpetrich

Reputation: 32316

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

Upvotes: 2

Related Questions