const char *_cFoo = "bar";
NSString *_foo = [[NSString alloc] initWithCString:_cFoo encoding:NSISOLatin1StringEncoding];
ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:url] autorelease];
[request setPostValue:_foo forKey:@"post_var"];
// ...
[request trigger];
[_foo release];
EDIT: I'm not sure why the above wouldn't work. I guess I should try it out. But looking at the source for ASIHTTPRequest, the -setPostValue:forKey:
method looks like it takes any NSObject
subclass for a POST value:
- (void)setPostValue:(id <NSObject>)value forKey:(NSString *)key
{
if (![self postData]) {
[self setPostData:[NSMutableDictionary dictionary]];
}
[[self postData] setValue:[value description] forKey:key];
[self setRequestMethod:@"POST"];
}
Perhaps convert an NSString
to a C string and use its NSData
representation as the POST variable value:
NSString *_foo = @"bar";
const char *_cFoo = [_foo cStringUsingEncoding:NSISOLatin1StringEncoding];
NSData *_cFooData = [NSData dataWithBytes:_cFoo length:strlen(_cFoo)];
[request setPostValue:_cFooData forKey:@"post_var"];