我想问一下iPhone应用程序目标C的问题。
我编写了一个程序来存储 cookie 并传递给另一个 URL 来检索 cookie。但是,我发现其中一个返回状态码是0。html的内容是空的。
谁能帮我?以下是我的代码。
// create a new mutable url
NSMutableURLRequest *request_get2 = [[[NSMutableURLRequest alloc] init] autorelease];
[request_get2 setURL:[NSURL URLWithString:@"http://www.example.com"]];
[request_get2 setHTTPMethod:@"GET"];
[request_get2 setValue:@"text/html; charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
[request_get2 setValue:@"http://www.example.com" forHTTPHeaderField:@"Referer"];
[request_get2 setHTTPShouldHandleCookies:YES];
// cookiesString is a string, the format is "cookieName=cookieValue;"
[request_get2 setValue: (NSString *) cookiesString forHTTPHeaderField:@"Cookie"];
// doGet - response
NSHTTPURLResponse *response_get2 = nil;
NSError *error_get2 = nil;
NSData *responseData_get2 = [NSURLConnection sendSynchronousRequest:request_get2 returningResponse:&response_get2 error:&error_get2];
NSString *data_get2 = [[NSString alloc]initWithData:responseData_get2 encoding:NSUTF8StringEncoding];
NSString *responseURL_get2 = [[response_get2 URL] absoluteString]; // null value
NSString *responseTextEncodingName_get2 = [response_get2 textEncodingName]; // null value
NSString *responseMIMEType_get2 = [response_get2 MIMEType]; // null value
NSUInteger *responseStatusCode_get2 = [response_get2 statusCode]; //[responseStatusCode intValue]; // the status code is 0
非常感谢你