0

我知道 http GET 可能会受到浏览器的限制,但是如果您使用的是 iPhone 怎么办?如果我做这样的事情有什么限制?

 NSString *urlString = [NSString stringWithFormat:@"http://www.hdsjskdjas.com/urlPop.php?vID=%@&pop=%d&tId=%@",videoId,pushPull,[objectSaver openWithKey:@"userId"]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]];
NSURLConnection *connect = [[NSURLConnection alloc] initWithRequest:request delegate:self];

if(connect) {
  //success;
} else {
    //failure;
}

使用这种方法向我的服务器发送信息 url 中的字符数限制是多少?

我希望能够向我的服务器发送超过24,000 个字符...

如果这是无法实现的,另一种选择是什么?

4

1 回答 1

2

要发送大量数据,您应该使用 POST 而不是 GET。以下是如何使用它的示例:

NSArray *keys = [NSArray arrayWithObjects:@"Content-Type", @"Accept", @"Authorization", nil]; 
NSArray *objects = [NSArray arrayWithObjects:@"application/json", @"application/json", mytoken, nil];
NSDictionary *headerFieldsDict = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
NSData *bodyData = [body dataUsingEncoding: NSUTF8StringEncoding];

NSMutableURLRequest *theRequest = [[[NSMutableURLRequest alloc] init] autorelease];
[theRequest setURL:[NSURL URLWithString:url]];
[theRequest setHTTPMethod:@"POST"];
[theRequest setTimeoutInterval:timeout];
[theRequest setAllHTTPHeaderFields:headerFieldsDict];
[theRequest setHTTPBody:bodyData]; 

NSLog(@"userSendURL URL: %@ \n",url);

self.conn = [[[NSURLConnection alloc] initWithRequest:theRequest delegate:self] autorelease];

在这种情况下,body 是一个简单的 NSString 对象,但它可以是您可以插入到 NSData 对象中的任何内容

于 2012-07-31T12:45:35.243 回答