-1

我如何在目标 c 中使用以下 CURL 命令,

curl -d lang=fr -d badge=0 http://www.redis.com/subscriber/J8lHY4X1XkU

提前致谢

4

2 回答 2

3

你可以试试:

NSURL *url = [NSURL URLWithString:@"http://www.redis.com/subscriber/J8lHY4X1XkU"];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];

NSString* str = @"lang=fr&badge=0";
NSData* body = [str dataUsingEncoding:NSUTF8StringEncoding];

[req setHTTPMethod:@"POST"];
[req setHTTPBody:body];
[req setValue:[NSString stringWithFormat:@"%d", [str length]] forHTTPHeaderField:@"Content-length"];

[[NSURLConnection alloc] initWithRequest:req delegate:self];

您可以在 iOS 文档中找到更多相关信息:NSURLConnectionNSMutableURLRequest

于 2013-04-16T10:35:21.770 回答
0

您可以尝试以下代码吗?

NSURL *url = [NSURL URLWithString:@"http://www.redis.com/subscriber/J8lHY4X1XkU?lang=fr&badge=0"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:120];
[request setURL:url];
[request setHTTPMethod:@"GET"];
NSData *responce = [NSURLConnection  sendSynchronousRequest:request returningResponse:NULL error:NULL];
于 2013-04-16T10:43:44.240 回答