문제

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.

도움이 되었습니까?

해결책

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];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top