Make url-encoded posts the default for ASIFormDataRequest
Add test for setting the charset of ASIFormDataRequests
Showing
3 changed files
with
60 additions
and
1 deletions
| @@ -39,7 +39,7 @@ | @@ -39,7 +39,7 @@ | ||
| 39 | - (id)initWithURL:(NSURL *)newURL | 39 | - (id)initWithURL:(NSURL *)newURL |
| 40 | { | 40 | { |
| 41 | self = [super initWithURL:newURL]; | 41 | self = [super initWithURL:newURL]; |
| 42 | - [self setPostFormat:ASIMultipartFormDataPostFormat]; | 42 | + [self setPostFormat:ASIURLEncodedPostFormat]; |
| 43 | [self setStringEncoding:NSUTF8StringEncoding]; | 43 | [self setStringEncoding:NSUTF8StringEncoding]; |
| 44 | return self; | 44 | return self; |
| 45 | } | 45 | } |
| @@ -121,6 +121,64 @@ | @@ -121,6 +121,64 @@ | ||
| 121 | GHAssertTrue(success,@"Failed to send the correct post data"); | 121 | GHAssertTrue(success,@"Failed to send the correct post data"); |
| 122 | } | 122 | } |
| 123 | 123 | ||
| 124 | +- (void)testCharset | ||
| 125 | +{ | ||
| 126 | + NSString *testString = @"£££s don't seem to buy me many €€€s these days"; | ||
| 127 | + | ||
| 128 | + // Test the default (UTF-8) with a url-encoded request | ||
| 129 | + NSString *charset = @"utf-8"; | ||
| 130 | + ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http://asi/ASIHTTPRequest/tests/formdata-charset"]]; | ||
| 131 | + [request setPostValue:testString forKey:@"value"]; | ||
| 132 | + [request start]; | ||
| 133 | + BOOL success = ([[request responseString] isEqualToString:[NSString stringWithFormat:@"Got data in %@: %@",charset,testString]]); | ||
| 134 | + GHAssertTrue(success,@"Failed to correctly encode the data"); | ||
| 135 | + | ||
| 136 | + // Test the default (UTF-8) with a multipart/form-data request | ||
| 137 | + request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http://asi/ASIHTTPRequest/tests/formdata-charset"]]; | ||
| 138 | + [request setPostValue:testString forKey:@"value"]; | ||
| 139 | + [request setPostFormat:ASIMultipartFormDataPostFormat]; | ||
| 140 | + [request start]; | ||
| 141 | + success = ([[request responseString] isEqualToString:[NSString stringWithFormat:@"Got data in %@: %@",charset,testString]]); | ||
| 142 | + GHAssertTrue(success,@"Failed to correctly encode the data"); | ||
| 143 | + | ||
| 144 | + // Test a different charset | ||
| 145 | + testString = @"£££s don't seem to buy me many $$$s these days"; | ||
| 146 | + charset = @"iso-8859-1"; | ||
| 147 | + request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http://asi/ASIHTTPRequest/tests/formdata-charset"]]; | ||
| 148 | + [request setPostValue:testString forKey:@"value"]; | ||
| 149 | + [request setStringEncoding:NSISOLatin1StringEncoding]; | ||
| 150 | + [request start]; | ||
| 151 | + success = ([[request responseString] isEqualToString:[NSString stringWithFormat:@"Got data in %@: %@",charset,testString]]); | ||
| 152 | + GHAssertTrue(success,@"Failed to correctly encode the data"); | ||
| 153 | + | ||
| 154 | + // And again with multipart/form-data request | ||
| 155 | + request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http://asi/ASIHTTPRequest/tests/formdata-charset"]]; | ||
| 156 | + [request setPostValue:testString forKey:@"value"]; | ||
| 157 | + [request setPostFormat:ASIMultipartFormDataPostFormat]; | ||
| 158 | + [request setStringEncoding:NSISOLatin1StringEncoding]; | ||
| 159 | + [request start]; | ||
| 160 | + success = ([[request responseString] isEqualToString:[NSString stringWithFormat:@"Got data in %@: %@",charset,testString]]); | ||
| 161 | + GHAssertTrue(success,@"Failed to correctly encode the data"); | ||
| 162 | + | ||
| 163 | + // Once more for luck | ||
| 164 | + charset = @"windows-1252"; | ||
| 165 | + request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http://asi/ASIHTTPRequest/tests/formdata-charset"]]; | ||
| 166 | + [request setPostValue:testString forKey:@"value"]; | ||
| 167 | + [request setStringEncoding:NSWindowsCP1252StringEncoding]; | ||
| 168 | + [request start]; | ||
| 169 | + success = ([[request responseString] isEqualToString:[NSString stringWithFormat:@"Got data in %@: %@",charset,testString]]); | ||
| 170 | + GHAssertTrue(success,@"Failed to correctly encode the data"); | ||
| 171 | + | ||
| 172 | + request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http://asi/ASIHTTPRequest/tests/formdata-charset"]]; | ||
| 173 | + [request setPostValue:testString forKey:@"value"]; | ||
| 174 | + [request setPostFormat:ASIMultipartFormDataPostFormat]; | ||
| 175 | + [request setStringEncoding:NSWindowsCP1252StringEncoding]; | ||
| 176 | + [request start]; | ||
| 177 | + success = ([[request responseString] isEqualToString:[NSString stringWithFormat:@"Got data in %@: %@",charset,testString]]); | ||
| 178 | + GHAssertTrue(success,@"Failed to correctly encode the data"); | ||
| 179 | + | ||
| 180 | +} | ||
| 181 | + | ||
| 124 | 182 | ||
| 125 | 183 | ||
| 126 | @end | 184 | @end |
-
Please register or login to post a comment