我試圖在iOS應用程序嘗試使用NSURL
我已經登錄到使用NSURLConnection
網站申請在objC GET請求,下面的代碼是在完成處理程序:
NSMutableURLRequest *requestGrades = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://mistar.oakland.k12.mi.us/novi/StudentPortal/Home/LoadProfileData/Assignments?_=1395809728907"]];
[requestGrades setHTTPMethod:@"GET"];
[NSURLConnection sendAsynchronousRequest:requestGrades queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *gradeResponse, NSData *gradeData, NSError *gradeError) {
if ([gradeData length] > 0 && gradeError == nil) {
NSLog(@"%@",requestGrades);
NSLog(@"grade Response = %@ \ngrade Data = %@", gradeResponse, [[NSString alloc] initWithData:gradeData encoding:NSUTF8StringEncoding]);
} else {
NSLog(@"grade Error = %@", gradeError);
}
}];
我在我的應用程序得到的迴應是這樣的:
grade Response = <NSHTTPURLResponse: 0x109627500> { URL: https://mistar.oakland.k12.mi.us/novi/StudentPortal/Home/LoadProfileData/Assignments?_=1395809728907 } { status code: 200, headers {
"Cache-Control" = "public, max-age=0";
Connection = "Keep-Alive";
"Content-Length" = 234;
"Content-Type" = "text/html; charset=utf-8";
Date = "Wed, 26 Mar 2014 05:21:52 GMT";
Expires = "Wed, 26 Mar 2014 05:21:52 GMT";
"Last-Modified" = "Wed, 26 Mar 2014 05:21:52 GMT";
Server = "Microsoft-IIS/7.5";
Vary = "*";
"X-AspNetMvc-Version" = "4.0";
"X-Powered-By" = "ASP.NET";
} }
其中,你可以看到,是不一樣的Chrome瀏覽器的響應(最值得注意的是,日e Content-Length
- 我只有234的長度 - 我希望像31189那樣)。
挖周圍的Chrome開發者工具的Network
部分,看着就當我嘗試請求數據什麼的鉻是:
鉻,當我點擊按鈕獲取一些數據,使得2 GET
請求(兩張圖片)。第一個獲取我想要爲我的應用獲得的數據,第二個獲得的數據看起來好像沒有做任何事情。但第二個chrome請求得到的響應與我嘗試從iOS發出第一個chrome請求時得到的響應相同(第一張圖片應返回31189的Content-Length
)。
所以我不知道我在做什麼錯我的NSURLConnection
。
Response = {URL:https://mistar.oakland.k12.mi.us/novi/StudentPortal/Home/LoadProfileData/Assignments?_ = 1395809728907} {狀態碼:200,頭部「Cache-Control」=「public,max-age = 0」; Connection =「Keep-Alive」; 「Content-Length」= 234; 「Content-Type」=「text/html; charset = utf-8」; Date =「Wed,26 Mar 2014 06:11:35 GMT」; 到期=「Wed,26 Mar 2014 06:11:35 GMT」; 「Last-Modified」=「Wed,26 Mar 2014 06:11:35 GMT」;; Server =「Microsoft-IIS/7.5」; Vary =「*」; 「X-AspNetMvc-Version」=「4.0」; 「X-Powered-By」=「ASP.NET」; }} –
AndrewSB
我只是再次查看了這兩個請求URL,我想我錯過了一些東西。它們都看起來像是一個'GET'請求到'https://mistar.oakland.k12.mi.us/novi/StudentPortal/Home/LoadProfileData/Assignments?_ = 1395809728907'。 – AndrewSB
對不起。