0

임 NSURLCacheStorageNotAllowed되어 반환 connection release method in connectionDidFinishLoading, causes errorNSMutableURLRequest는 이전 값도 cachePolicy가 여기에 게시 코드를 사용하여


이제 첫 번째 로그 didFail 반환을 실행합니다. 초 실행; 이전 응답 데이터를 반환합니다. 내 (로컬 호스트) 서버가 완전히 오프라인 상태입니다. 및 cachePolicy (나는 위의 게시 된 링크 코드 확인)

NSMutableURLRequest *request= 
[NSMutableURLRequest requestWithURL:url 
cachePolicy:NSURLCacheStorageNotAllowed timeoutInterval:3.0f]; 

응답 데이터가 어딘가에 캐시 여전히 존재하는 것 같다 NSURLCacheStorageNotAllowed입니다.

하지만 -not이

하지 반환 된 캐시를 implemented- 나는 댓글을 달았되는 // NSURLRequestReloadIgnoringLocalAndRemoteCacheData를 사용하는 경우.
NSURLRequestReloadIgnoringLocalAndRemoteCacheData

NSURLCacheStorageNotAllowed

내가 무엇을해야한다

하지만 그렇게 의 차이가 무엇인지 경우

?

+0

http://stackoverflow.com/questions/18351491/how-to-wait-response-and-parse-xml-done-in-afnetworking-ios/18351761#18351761 –

+0

나머지 http://stackoverflow.com/ questions/18245461/ios-restkit-application-design/18246517 # 18246517 –

답변

0

있는 NSString * 포스트 =보십시오 [[있는 NSString의 ALLOC] initWithFormat를 "포스트 매개 변수"@] NSURL * Url = [NSURL URLWithString : @ "URL"];

NSData *PostData = [Post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; 

    NSString *postLength = [NSString stringWithFormat:@"%d", [PostData length]]; 

    NSMutableURLRequest *Request = [[NSMutableURLRequest alloc] init]; 
    [Request setURL:Url]; 
    [Request setHTTPMethod:@"POST"]; 
    [Request setValue:postLength forHTTPHeaderField:@"Content-Length"]; 
    [Request setValue:@"application/json" forHTTPHeaderField:@"Accept"]; 
    [Request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; 
    [Request setHTTPBody:PostData]; 
    NSError *error; 
    NSURLResponse *response; 

    NSData *Result = [NSURLConnection sendSynchronousRequest:Request returningResponse:&response error:&error]; 
    if (!Result) 
    { 
     NSLog(@"Error"); 
    } 
    else 
    { 
     //Parse the result 
    } 
+0

예는 동기식입니다. 서버 수신이 완료 될 때까지 응용 프로그램이 중단됩니다. 질문은 NSURLCacheStorageNotAllowed가 허용하는 이유는 무엇입니까? 서버가 오프라인 인 경우에도 이전 캐시 데이터를 반환합니다. 답변이 질문과 관련이 없습니다. 다른 방법으로 이것을 전달하는 방법이 필요하지 않습니다. 이유를 알기를 바랍니다. –

2

NSURLCacheStorageNotAllowedNSCachedURLResponse을 참조하여 ENUM NSURLCacheStoragePolicy의 값이다. 캐시 정책이 NSMutableURLRequest이기 때문에 열거 형 (NSURLRequestCachePolicy) 일 뿐이므로 NSMutableURLRequest이라는 정적 메서드에 잘못된 int를 전달하면됩니다. 이 경우에 NSURLCacheStorageNotAllowed은 단지 2입니다. 이는 NSURLRequestReturnCacheDataElseLoad과 같으며, 이것이 오래된 데이터를 얻은 이유입니다.