我想要做一個簡單的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