views:

42

answers:

2

Hi i'm trying to give a request to the url in iphone sdk the http method is POST. The http body contains some escape characters

NSString *requestMessage=[NSString stringWithString:@"?username/u001password/u001description"];
    NSMutableURLRequest *url=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://welcome.com"]];
    [url setHTTPMethod:@"POST"];
    [url setHTTPBody:[requestMessage dataUsingEncoding:NSUTF8StringEncoding]];
     NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:url delegate:self];

the escape character here is /u001

by this code i didn't get any correct response. i thing its wrong with the escape characters only. plz give me a solution for how to give escape sequence in cocoa. Thanks in advance

A: 

What do you want to escape? I don't quite understand what you are trying to do. Do you want to write "&"? Then do it. It's not HTML.

Besides that, [NSString stringWithString:@"…constant string…"] is superfluid. @"…constant string…" is all you need.

There is a method in NSString to add percent-escapes to URLs: -(void)stringByAddingPercentEscapesUsingEncoding:. Maybe that's what you're looking for?

Christian
A: 

You've confused forward slashes (/) with backslashes (\). You need a backslash to form an escape sequence; a slash is just a slash, and “/u001” is just a slash, the letter u, two digits zero, and a digit one.

That said, if you actually want to include U+0001 in your string, even \u001 is wrong. You want \x01 or maybe \u0001 (but I seem to remember that GCC complains if you use \u for a character lower than U+0100).

I do wonder why the server would require U+0001 as the separator, though. Are there public API docs for whatever server you're querying?

Peter Hosey