1

我正在尝试解析 xml,但我有一个问题:

NSString *url = [NSString stringWithFormat:@"http://ipadress/web_service/list.php?DATE=%@",dateSinc];
NSMutableURLRequest *request =[[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:url]];
[request setHTTPMethod:@"GET"];

NSURLConnection *conn=[[NSURLConnection alloc] initWithRequest:request delegate:self];
if (conn) {
    webData = [[NSMutableData data] retain];
}
else{

}

当 dateSinc 是2013-02-04示例时,它可以工作,但在2013-02-04 09:47:00时它不起作用(连接没有响应)......但在浏览器中工作......

4

1 回答 1

2

我认为问题与未正确编码 URL 有关,因此 Web 服务器没有看到您想要的日期:

NSString *url = [NSString stringWithFormat:@"http://ipadress/web_service/list.php?DATE=%@",dateSinc];
NSString *encodedURL = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSMutableURLRequest *request =[[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:encodedURL]];
// etc.
于 2013-02-18T13:44:05.887 回答