Frage

I want to translate the following GET request to an instance of NSMutableURLRequest:

curl -X GET \
  -H "X-Parse-Application-Id: sdasfasdf" \
  -H "X-Parse-REST-API-Key: asdfasdfasdfasd" \
  -G \
  --data-urlencode 'where={"arrayKey":2}' \
  https://api.parse.com/1/classes/RandomObject

I know how to set the headers and the method, but not how to add the --data-urlencode part.

Can anyone help me with this? Thanks.

War es hilfreich?

Lösung

You may encode the string using the -[NSString stringByAddingPercentEscapesUsingEncoding:] method. Then, you just need to append the string to the URL.

NSString *URLPrefix = @"https://api.parse.com/1/classes/RandomObject";
NSString *encodedQuery = [@"where={\"arrayKey\":2}" stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSURL *URL = [NSURL URLWithString:[NSString stringWithFormat:@"%@?%@", URLPrefix, encodedQuery]];
[request setURL:URL];
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top