Hello,
I want to ask about the iPhone application objective C problem.
I wrote a program to store the cookies and pass to another URL to retrieve the cookies. However, I found that one of the return status code is 0. The content of the html is empty.
Can any one help me? The following is my code.
// 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
Thank you very much