【发布时间】:2015-02-23 09:56:13
【问题描述】:
我正在尝试使用模拟器而不是真实设备在 iOS(目标 C)中进行简单的获取。
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 时,这段代码可以完美运行。当我尝试使用更长(大约 4000 个字符)url 的代码时,代码不起作用(不打印错误)。
我知道帖子更适合这种事情,但我的问题是,这是从获取请求中预期的吗?
另外,我的 url 在我的 mac 和 iOS 浏览器中完美运行。
【问题讨论】:
-
也许检查
newRequest的 URL 是否有效(也许有些转义似乎是错误的)。 -
我已经在日志中打印了
theGetURL,我已经在模拟器浏览器上对其进行了测试,它可以按预期工作。 -
从你的意思来看,你打印的是
NSString,但不是[NSURL URLWithString:theGetURL]? -
NSLog(@"The URL:%@", [NSURL URLWithString:theGetURL]);返回空值。我做得对吗? -
检查
stringByAddingPercentEscapesUsingEncoding:stackoverflow.com/questions/3418754/…
标签: ios objective-c