我送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) –