我正在尝试通过数据库上的 HTTP Post webservice 获取 CSV 文件,以便我可以解析它。我目前有这个代码
-(void)viewDidLoad{
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://192.x.x.x/xyz.php?cmd=select * from record and datetime>'%@ 00:00:00' and datetime<'%@ 23:59:59' order by id limit 15", startDate, endDate]]];
[request setHTTPMethod:@"POST"];
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if(conn)
{
NSLog(@"Connection Successful");
}
else
{
NSLog(@"Connection could not be made");
}}
////////////////////////////
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
NSLog(@"Did Receive Data method was called");
NSString *contentString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
csvParser = [[CHCSVParser alloc] initWithContentsOfCSVFile:contentString];
ParserDelegate *parserDelegate = [[ParserDelegate alloc] initParser];
[csvParser setDelegate: parserDelegate];
[csvParser parse];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(@"Error: %@", error);
}
这是我从调试日志中得到的
Command string: http://192.x.x.x/xyz.php?cmd=select * from record and datetime>'2003-10-30 08:00:00 +0000 00:00:00' and datetime<'2013-10-29 07:00:00 +0000 23:59:59' order by id limit 15
[615:c07] Connection Successful
[615:c07] Error: Error Domain=NSURLErrorDomain Code=-1000 "bad URL" UserInfo=0x7561fd0 {NSUnderlyingError=0x71eb1c0 "bad URL", NSLocalizedDescription=bad URL}
我收到了这个错误的 URL。我可以通过网络浏览器访问 URL(浏览器可能会做一些事情)。有谁知道问题是什么以及如何解决?
谢谢