Hi I have made a code which gives me an url with a date at the end like http://www.google.com/2012-10-09
But for some reason it doesn’t redirect me to the correct url?
It seems like there is some problem understanding NSURL URLwithstring?
Here is my code
- (IBAction)sedato:(id)sender {
//Finds date and make string
NSDate *ddato = [_datepickout date];
NSString *vdato = [NSString stringWithFormat:@"%@", ddato];
NSDateFormatter *datoform = [[NSDateFormatter alloc] init];
[datoform setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];
[datoform setDateFormat: @"yyyy-MM-dd HH:mm:ss Z"];
NSDate *datemedform = [datoform dateFromString: vdato];
NSString *strdate = [[NSString alloc] initWithFormat:@"%@", datemedform];
NSArray *arr = [strdate componentsSeparatedByString:@" "];
NSString *endelig;
endelig = [arr objectAtIndex:0];
NSArray *arr2 = [endelig componentsSeparatedByString:@"-"];
NSString *year;
year = [arr2 objectAtIndex:0];
NSString *mm;
mm = [arr2 objectAtIndex:1];
NSString *dag;
day = [arr2 objectAtIndex:2];
NSString *url = [NSString stringWithFormat:@"http://www.coutbound.dk/logon/add_date.asp?view_date=%@/%@/%@",year,mm,day];
//Send url request with string
ASIFormDataRequest *request2 = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:url]];
[request2 setUseKeychainPersistence:YES];
[request2 setUseCookiePersistence:YES];
[request2 setDelegate:self];
[request2 startAsynchronous];
}
- (void)requestFinished:(ASIHTTPRequest *)request {
NSLog(@"Saved form successfully");
NSLog(@"Response was:");
NSLog(@"%@",[request responseString]);
NSLog(@"HEADERS: %@",[request responseHeaders]);
NSLog(@"STATUSCODE: %u",[request responseStatusCode]);
NSLog(@"COOkies: %@",[request responseCookies]);
}
You are converting the date to string, then back to date, back to string, to components then again to string! There must be an error somewhere.
Try this instead:
Check the result with