首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用数据采集器制作url字符串

用数据采集器制作url字符串
EN

Stack Overflow用户
提问于 2012-10-11 23:33:05
回答 1查看 95关注 0票数 0

嗨,我做了一个代码,给我一个网址,上面有一个日期,比如www.google.com/2012-10-09

但出于某种原因它并没有把我转到正确的网址上?似乎有一些问题来理解NSURL URLwithstring?

这里是我的代码

代码语言:javascript
复制
- (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]);
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-10-12 00:48:14

您正在将日期转换为字符串,然后返回日期,返回到字符串,再转换为组件,然后再转换为字符串!一定有什么地方出错了。

试一试:

代码语言:javascript
复制
NSDate *myDate = [_datePicker date];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"yyyy/MM/dd";
NSString *dateStr = [formatter stringFromDate:myDate];
NSString *url = [NSString stringWithFormat:@"%@%@", urlBase, dateStr];

代码语言:javascript
复制
NSLog(@"URL: %@", url);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12850183

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档