Browse Source

测试cms发送

临城职教中职
liangkun 2 years ago
parent
commit
243db39d17
2 changed files with 28 additions and 22 deletions
  1. +3
    -5
      Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.OA/News/NewsService.cs
  2. +25
    -17
      Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Util/Learun.Util/Web/HttpMethods.cs

+ 3
- 5
Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.OA/News/NewsService.cs View File

@@ -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<Root>(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 + "') ");
}
}



+ 25
- 17
Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Util/Learun.Util/Web/HttpMethods.cs View File

@@ -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;
}
}
}

Loading…
Cancel
Save