Objective-C
Objective-C
Send a Form-URL-Encoded REST Request
See more REST Examples
Demonstrates Rest.FullRequestFormUrlEncoded, which sends an application/x-www-form-urlencoded request. The body is built from the query parameters added to the object, and the response body is returned as text.
Background. For a form-url-encoded request the accumulated parameters become the request body rather than the URL query string. This matches the encoding used by HTML form POSTs.
Chilkat Objective-C Downloads
#import <CkoRest.h>
#import <NSString.h>
BOOL success = NO;
CkoRest *rest = [[CkoRest alloc] init];
BOOL bTls = YES;
BOOL bAutoReconnect = YES;
success = [rest Connect: @"example.com" port: [NSNumber numberWithInt: 443] tls: bTls autoReconnect: bAutoReconnect];
if (success == NO) {
NSLog(@"%@",rest.LastErrorText);
return;
}
// The application/x-www-form-urlencoded body is built from the query parameters added to the object.
[rest AddQueryParam: @"username" value: @"alice"];
[rest AddQueryParam: @"action" value: @"login"];
// Send the form-url-encoded request. The parameters become the request body rather than the URL
// query string.
NSString *responseText = [rest FullRequestFormUrlEncoded: @"POST" uriPath: @"/api/login"];
if (rest.LastMethodSuccess == NO) {
NSLog(@"%@",rest.LastErrorText);
return;
}
NSLog(@"%@",responseText);