forked from eklipse2k8/CocoaRestClient
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCRCFormEncodedRequest.m
More file actions
40 lines (33 loc) · 1.22 KB
/
Copy pathCRCFormEncodedRequest.m
File metadata and controls
40 lines (33 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//
// CRCFormEncodedRequest.m
// CocoaRestClient
//
// Created by Adam Venturella on 7/10/10.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import "CRCFormEncodedRequest.h"
#import "CocoaRestClientAppDelegate.h"
@implementation CRCFormEncodedRequest
+(void)createRequest:(NSMutableURLRequest *)request
{
CocoaRestClientAppDelegate * delegate = (CocoaRestClientAppDelegate *)[[NSApplication sharedApplication] delegate];
NSMutableData * body = [NSMutableData data];
NSString * headerfield = @"application/x-www-form-urlencoded";
[request addValue:headerfield forHTTPHeaderField:@"Content-Type"];
if([delegate.paramsTable count] > 0)
{
for(NSDictionary * row in delegate.paramsTable)
{
NSString * key = [row objectForKey:@"key"];
NSString * value = [row objectForKey:@"value"];
if([body length] > 0)
[body appendData:[@"&" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"%@=%@",
[key stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
[value stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]
dataUsingEncoding:NSUTF8StringEncoding]];
}
}
[request setHTTPBody: body];
}
@end