From 243db39d17ecfce91658d8cee641fe53a435b450 Mon Sep 17 00:00:00 2001 From: liangkun Date: Tue, 15 Mar 2022 11:06:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95cms=E5=8F=91=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Learun.Application.OA/News/NewsService.cs | 8 ++-- .../Learun.Util/Web/HttpMethods.cs | 42 +++++++++++-------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.OA/News/NewsService.cs b/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.OA/News/NewsService.cs index 35fa42b1e..bbd34ee64 100644 --- a/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.OA/News/NewsService.cs +++ b/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.OA/News/NewsService.cs @@ -251,8 +251,7 @@ namespace Learun.Application.OA string responses = HttpMethods.HttpPosts("http://" + ports + "/api/v1/contents/" + siteId + "/" + channelId, SendNew.ToJson(), ApiId); BaseRepository() - .ExecuteBySql("insert INTO LR_Base_Log(F_LogId,F_CategoryId,F_SourceContentJson),VALUES (newid(),,'2222','" + - responses + "') "); + .ExecuteBySql("insert INTO LR_Base_Log(F_LogId,F_CategoryId,F_SourceContentJson),VALUES (newid(),'2222','"+responses+"') "); //#region 修改审核状态 //string Nid = JsonConvert.DeserializeObject(responses).value.id; @@ -273,11 +272,10 @@ namespace Learun.Application.OA //#endregion } } - catch (ArithmeticException ex) + catch (Exception ex) { BaseRepository() - .ExecuteBySql("insert INTO LR_Base_Log(F_LogId,F_CategoryId,F_SourceContentJson),VALUES (newid(),'2222','" + - ex.Message + "') "); + .ExecuteBySql("insert INTO LR_Base_Log(F_LogId,F_CategoryId,F_SourceContentJson),VALUES (newid(),'2222','"+ex.Message + "') "); } } diff --git a/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Util/Learun.Util/Web/HttpMethods.cs b/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Util/Learun.Util/Web/HttpMethods.cs index 6e1f9085d..a177705c6 100644 --- a/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Util/Learun.Util/Web/HttpMethods.cs +++ b/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Util/Learun.Util/Web/HttpMethods.cs @@ -152,28 +152,36 @@ namespace Learun.Util public static string HttpPosts(string url, string json, WebHeaderCollection header) { string result = ""; - HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); - req.Method = "POST"; - req.ContentType = "application/json;charset=UTF-8"; - req.Headers.Add(header); - byte[] data = Encoding.UTF8.GetBytes(json);//把字符串转换为字节 + try + { + HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); + req.Method = "POST"; + req.ContentType = "application/json;charset=UTF-8"; + req.Headers.Add(header); + byte[] data = Encoding.UTF8.GetBytes(json);//把字符串转换为字节 - req.ContentLength = data.Length; //请求长度 + req.ContentLength = data.Length; //请求长度 - using (Stream reqStream = req.GetRequestStream()) //获取 - { - reqStream.Write(data, 0, data.Length);//向当前流中写入字节 - reqStream.Close(); //关闭当前流 - } + using (Stream reqStream = req.GetRequestStream()) //获取 + { + reqStream.Write(data, 0, data.Length);//向当前流中写入字节 + reqStream.Close(); //关闭当前流 + } - HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); //响应结果 - Stream stream = resp.GetResponseStream(); - //获取响应内容 - using (StreamReader reader = new StreamReader(stream, Encoding.UTF8)) + HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); //响应结果 + Stream stream = resp.GetResponseStream(); + //获取响应内容 + using (StreamReader reader = new StreamReader(stream, Encoding.UTF8)) + { + result = reader.ReadToEnd(); + } + return result; + } + catch (Exception e) { - result = reader.ReadToEnd(); + throw e; } - return result; + } } }