1

データを取得するために、アプリケーションから 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);

    }

ただし、コードをアップグレードしたため、これは機能しません。このコードを持つ古いアプリケーションは引き続き機能しますが、新しいアプリケーションを作成してこのコードを投稿すると、エラーが発生します

  [responseData setLength:0];

    [responseData appendData:data];

NSString の目に見える @interface が setLength または appenddata を宣言していないことを示しています。

これが機能しない理由を誰かに教えてもらえますか?

前もって感謝します

4

2 に答える 2

2

これにショートさせた

-(void) testme: (NSString *) link{
NSURL * url = [NSURL URLWithString:link];
NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:url];
[request addValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setHTTPMethod:@"GET"];
[[NSURLConnection alloc]initWithRequest:request delegate:self startImmediately:YES];

}

そして、メソッドは

    - (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 {

    NSString *s = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    NSLog(@"%@", s);

}

正常に動作します

于 2012-05-04T15:04:46.220 に答える
0

あなたの responseData インスタンス変数が何らかの形で NSString に型キャストされているように思えます。responseData ivar はどのように定義されていますか? また、投稿したデリゲートを除いて、他の操作を行っていますか?

于 2012-05-04T14:22:00.533 に答える