2012-07-31 56 views
0

我知道http GET可以被浏览器限制,但如果您使用的是iPhone?如果我做这样的事情有什么限制?http GET GET Limit(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中的字符数?

我希望能够通过24000字符到我的服务器发送...

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

回答

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]; 

在这种情况下,身体是一个简单的NSString对象,但它可以是任何东西,你可以在一个NSData对象插入现在

+0

我怎么会引用数据在我的PHP代码? $ _POST [ 'whatGoesHere']; – 2012-07-31 12:53:08

+0

在此示例中,POST流中的数据行为。我从来没有使用PHP,但可能是这个链接可能对你有用http://stackoverflow.com/questions/3362145/i-cant-read-my-post-http-requests-body-with-php 如果你仍然想要使用键值来设置NSString *正文: NString body = [NSString stringWithFormat:@“vID =%@&pop =%d&tId =%@”,videoId,pushPull,[objectSaver openWithKey:@“userId” ]]; 你可以在wikipedia中找到更多关于HTTP POST的信息:http://en.wikipedia.org/wiki/POST_(HTTP) – melopsitaco 2012-07-31 13:10:03