我送JSON数据到服务器,并得到错误发送JSON数据到服务器
JSON -
- { GETDatetime = “/日期(1354119549)/”; }
错误 -
- 服务器遇到错误处理请求。异常消息是'SqlDateTime溢出。必须介于1/1/1753 12:00:00 AM和12/31/9999 11:59:59 PM之间。在OBJ-C
代码
NSString* json = [dict JSONRepresentation];
//NSString *myRequestString = @"param="; // Attention HERE!!!!
//myRequestString = [myRequestString stringByAppendingString:json];
NSURL *url = [NSURL URLWithString:reqUrlStr];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
NSData *requestData = [NSData dataWithBytes:[json UTF8String] length:[json length]];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:[NSString stringWithFormat:@"%d", [requestData length]] forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody: requestData];
请显示如何形成日期值。我的习惯是使用nsdateformatter格式化为一个字符串,这很容易被我的服务器解析。 – danh
[链接](http://stackoverflow.com/questions/6306718/nstimeinterval-format-for-post-with-json-objective-c-to-datetime-net-format) –