일부 데이터를 가져 오기 위해 내 애플리케이션에서 HTTPS 요청을해야합니다. 나는 여기에 내 코드, 여전히 작동이 코드를 가지고 내 이전 응용 프로그램을 업그레이드하기 때문에이 작동하지 않습니다Cocoa/objective-C로 HTTPS 요청
-(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);
}
이 방법을 사용하여 할 수있을하는 데 사용하지만, 나는 새로운 응용 프로그램과 포스 테이를 만들 경우 나는 코드 그것은있는 NSString에 대한 가시적 인 @interface이 SetLength를 또는 대한 appendData를 선언 없다고 말합니다
[responseData setLength:0];
및
[responseData appendData:data];
주위에 오류가 발생합니다.
누군가가 왜 이것이 작동하지 않는지 말할 수 있습니까?
가 관리 잘 작동됩니다 : D – AdamM