@Aiti
2020-06-23T10:15:34.000000Z
字数 1364
阅读 243
WebApi
原因:前端调用API时传入的国际(UTC)时间,时间格式参数为:2000-06-26T16:00:00Z,而中国地区的比国际时间少8个小时。
解决:在Controller中如果请求的参数类型为时间类型的话,DateTime.Kind会是UTC,中国地区的会减少8个小时,所以需要调整一下WebApiConfig,将其设置为Local本地时间。对应的json序列化缺少设置就会少八小时。
(1).通过API自带的ResultFul请求模式序列化
//json 序列化设置GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings = new Newtonsoft.Json.JsonSerializerSettings(){NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, //设置忽略值为 null 的属性DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Local,//DateFormatString="yyyy-MM-dd HH:mm:ss",//DateFormatHandling=Newtonsoft.Json.DateFormatHandling.MicrosoftDateFormat,};
(2)自定义的json序列化
//JSON序列化设置JsonSerializerSettings setting = new JsonSerializerSettings();JsonConvert.DefaultSettings = new Func<JsonSerializerSettings>(() =>{//日期类型默认格式化处理setting.DateTimeZoneHandling = DateTimeZoneHandling.Local;//空值处理setting.NullValueHandling = NullValueHandling.Ignore;return setting;});
遇到问题:APP请求上传带图片,报错,不带图片上传成功。图片过大也报错。但是小提琴可以上传图片成功。
1.照下面的节点进行 添加 10MB大小
<system.webServer><serverRuntime uploadReadAheadSize="10485760" /></system.webServer>
2.设置在IIS->配置配置器->system.webServer->serverRuntime->uploadReadAheadSize
因为本地IIS没有证书,正式网备案了,有证书,所以本地使用debug发布测试,不要使用Release。
且前端APP分了两个板块,01Login和02Main连接的URL都要对应的服务地址;然后01Login用HBuilder启动;02Main打包放到对应的服务根目录“ModulesDownload”文件下,并修改根目录appversion对应的版本