我需要從我的應用程序發出一個HTTPS請求來獲取一些數據。我曾經能在這裏使用這種方法HTTPS請求可可/ objective-C
-(void)Authenticate
{
self.responseData = [NSMutableData data];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://10.84.4.2:8444/fish-mobile/GetPIN.jsp?MSISDN=12345"]];
//NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[responseData setLength:0];
}
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge: (NSURLAuthenticationChallenge *)challenge {
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[responseData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
self.responseData = nil;
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(@"%@", responseString);
}
但是自從我升級我的代碼,我有這個代碼仍然有效舊的應用程序,這是不工作做,但如果我創建一個新的應用程序和郵政這在我的代碼繞過
[responseData setLength:0];
和
[responseData appendData:data];
錯誤報告說,爲的NSString沒有明顯的@interface聲明setLength或appenddata。
有人能告訴我爲什麼這不起作用嗎?
在此先感謝
設法得到它排序:d – AdamM