我想要做一个简单的iOS(目标C)使用模拟器而不是一个真正的设备。iOS的HTTP'获得'有一个URL长度限制
NSMutableURLRequest *newRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:theGetURL]
cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
timeoutInterval:10];
[newRequest setHTTPMethod: @"GET"];
NSError *requestError2;
NSURLResponse *urlResponse2;
NSData *response2 = [NSURLConnection sendSynchronousRequest:newRequest returningResponse:&urlResponse2 error:&requestError2];
NSString* secondResponse = [[NSString alloc] initWithData:response2 encoding:NSUTF8StringEncoding];
NSLog(@"error = %@",requestError.localizedDescription);
NSLog(@"response=%@",secondResponse);
NSLog(@"url response = %@",urlResponse);
当我传递一个简单的URL时,此代码完美工作。当我用较长的URL(大约4000个字符)尝试代码时,代码不起作用(不打印错误)。
我知道一个帖子更适合这种事情,但我的问题是,这是从一个获取请求的预期?
此外,我的网址在我的Mac和iOS浏览器中完美工作。
也许检查'newRequest'的URL是否有效(可能是一些转义,这似乎是错误的)。 – Larme 2015-02-23 10:00:44
我已经在日志中打印了'theGetURL',并且已经在模拟器浏览器上进行了测试,并且按预期工作。 – danb 2015-02-23 10:03:43
从你说的是什么,你已经打印了'NSString',但不是'[NSURL URLWithString:theGetURL]'? – Larme 2015-02-23 10:04:44