`1112
This commit is contained in:
		
							parent
							
								
									20904bda17
								
							
						
					
					
						commit
						0202812af6
					
				|  | @ -3,6 +3,8 @@ using System.Collections.Generic; | ||||||
| using System.IO; | using System.IO; | ||||||
| using System.Linq; | using System.Linq; | ||||||
| using System.Net; | using System.Net; | ||||||
|  | using System.Net.Security; | ||||||
|  | using System.Security.Cryptography.X509Certificates; | ||||||
| using System.Text; | using System.Text; | ||||||
| using System.Threading.Tasks; | using System.Threading.Tasks; | ||||||
| 
 | 
 | ||||||
|  | @ -55,60 +57,41 @@ namespace BLL.Common | ||||||
|             } |             } | ||||||
|             return strPostReponse; |             return strPostReponse; | ||||||
|         } |         } | ||||||
| 
 |         private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) | ||||||
| 
 |  | ||||||
|         public static string HttpPost(string Url, string jsonParas) |  | ||||||
|         { |         { | ||||||
|             string strURL = Url; |             return true; //总是接受    | ||||||
|             //创建一个HTTP请求   |  | ||||||
|             HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strURL); |  | ||||||
|             //Post请求方式   |  | ||||||
|             request.Method = "POST"; |  | ||||||
|             //内容类型 |  | ||||||
|             request.ContentType = "application/x-www-form-urlencoded"; |  | ||||||
| 
 |  | ||||||
|             //设置参数,并进行URL编码  |  | ||||||
| 
 |  | ||||||
|             string paraUrlCoded = jsonParas;//System.Web.HttpUtility.UrlEncode(jsonParas);    |  | ||||||
| 
 |  | ||||||
|             byte[] payload; |  | ||||||
|             //将Json字符串转化为字节   |  | ||||||
|             payload = System.Text.Encoding.UTF8.GetBytes(paraUrlCoded); |  | ||||||
|             //设置请求的ContentLength    |  | ||||||
|             request.ContentLength = payload.Length; |  | ||||||
|             //发送请求,获得请求流  |  | ||||||
| 
 |  | ||||||
|             Stream writer; |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 writer = request.GetRequestStream();//获取用于写入请求数据的Stream对象 |  | ||||||
|             } |  | ||||||
|             catch (Exception) |  | ||||||
|             { |  | ||||||
|                 writer = null; |  | ||||||
|                 BLL.ErrLogInfo.WriteLog("连接服务器失败!"); |  | ||||||
|             } |  | ||||||
|             //将请求参数写入流 |  | ||||||
|             writer.Write(payload, 0, payload.Length); |  | ||||||
|             writer.Close();//关闭请求流 |  | ||||||
|                            // String strValue = "";//strValue为http响应所返回的字符流 |  | ||||||
|             HttpWebResponse response; |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 //获得响应流 |  | ||||||
|                 response = (HttpWebResponse)request.GetResponse(); |  | ||||||
|             } |  | ||||||
|             catch (WebException ex) |  | ||||||
|             { |  | ||||||
|                 response = ex.Response as HttpWebResponse; |  | ||||||
|             } |  | ||||||
|             Stream s = response.GetResponseStream(); |  | ||||||
|             //  Stream postData = Request.InputStream; |  | ||||||
|             StreamReader sRead = new StreamReader(s); |  | ||||||
|             string postContent = sRead.ReadToEnd(); |  | ||||||
|             sRead.Close(); |  | ||||||
|             return postContent;//返回Json数据 |  | ||||||
|         } |         } | ||||||
|  | 
 | ||||||
|  |         public static string PostJsonByHttps(string url, string jsonParams) | ||||||
|  |         { | ||||||
|  |             ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; | ||||||
|  |             HttpWebRequest request = null; | ||||||
|  |             CookieContainer cookie = new CookieContainer(); | ||||||
|  |             //HTTPSQ请求 | ||||||
|  |             ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult); | ||||||
|  |             request = WebRequest.Create(url) as HttpWebRequest; | ||||||
|  |             request.CookieContainer = cookie; | ||||||
|  |             request.ProtocolVersion = HttpVersion.Version11; | ||||||
|  |             request.Method = "POST"; | ||||||
|  |             request.ContentType = "application/x-www-form-urlencoded"; | ||||||
|  |             request.KeepAlive = true; | ||||||
|  |             byte[] byteData = Encoding.UTF8.GetBytes(jsonParams); | ||||||
|  |             int length = byteData.Length; | ||||||
|  |             request.ContentLength = length; | ||||||
|  | 
 | ||||||
|  |             using (Stream stream = request.GetRequestStream()) | ||||||
|  |             { | ||||||
|  |                 stream.Write(byteData, 0, byteData.Length); | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             var response = (HttpWebResponse)request.GetResponse(); | ||||||
|  | 
 | ||||||
|  |             using (StreamReader st = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8"))) | ||||||
|  |             { | ||||||
|  |                 return st.ReadToEnd().ToString(); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         private static HttpWebRequest CreateHttpRequest(string url, string requestType, string token, params object[] strJson) |         private static HttpWebRequest CreateHttpRequest(string url, string requestType, string token, params object[] strJson) | ||||||
|         { |         { | ||||||
|             HttpWebRequest request = null; |             HttpWebRequest request = null; | ||||||
|  |  | ||||||
|  | @ -2,7 +2,7 @@ | ||||||
| <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||||||
|   <PropertyGroup> |   <PropertyGroup> | ||||||
|     <ProjectView>ProjectFiles</ProjectView> |     <ProjectView>ProjectFiles</ProjectView> | ||||||
|     <LastActiveSolutionConfig>Release|Any CPU</LastActiveSolutionConfig> |     <LastActiveSolutionConfig>Debug|Any CPU</LastActiveSolutionConfig> | ||||||
|     <UseIISExpress>true</UseIISExpress> |     <UseIISExpress>true</UseIISExpress> | ||||||
|     <Use64BitIISExpress> |     <Use64BitIISExpress> | ||||||
|     </Use64BitIISExpress> |     </Use64BitIISExpress> | ||||||
|  |  | ||||||
|  | @ -9,7 +9,7 @@ | ||||||
|     <section name="FineUIPro" type="FineUIPro.ConfigSection, FineUIPro" requirePermission="false"/> |     <section name="FineUIPro" type="FineUIPro.ConfigSection, FineUIPro" requirePermission="false"/> | ||||||
|   </configSections> |   </configSections> | ||||||
|   <connectionStrings> |   <connectionStrings> | ||||||
|     <add name="FCLDBConnectionString" connectionString="Data Source=.\sql2016;Initial Catalog=FCLDB;uid=sa;pwd=1111;" providerName="System.Data.SqlClient"/> |     <add name="FCLDBConnectionString" connectionString="Data Source=.;Initial Catalog=FCLDB;uid=sa;pwd=Sh@nghai9;" providerName="System.Data.SqlClient"/> | ||||||
|   </connectionStrings> |   </connectionStrings> | ||||||
|   <FineUIPro DebugMode="false" CustomTheme="Metro_Dark_Blue" EnableAnimation="true" JSLibrary="All"/> |   <FineUIPro DebugMode="false" CustomTheme="Metro_Dark_Blue" EnableAnimation="true" JSLibrary="All"/> | ||||||
|   <appSettings> |   <appSettings> | ||||||
|  | @ -54,7 +54,7 @@ | ||||||
|       <add path="res.axd" verb="GET" type="FineUIPro.ResourceHandler, FineUIPro" validate="false"/> |       <add path="res.axd" verb="GET" type="FineUIPro.ResourceHandler, FineUIPro" validate="false"/> | ||||||
|       <add path="ChartImg.axd" verb="GET,POST,HEAD" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/> |       <add path="ChartImg.axd" verb="GET,POST,HEAD" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/> | ||||||
|     </httpHandlers> |     </httpHandlers> | ||||||
|     <compilation debug="false" targetFramework="4.6.1"> |     <compilation debug="true" targetFramework="4.6.1"> | ||||||
|       <buildProviders> |       <buildProviders> | ||||||
|         <add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.WebForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/> |         <add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.WebForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/> | ||||||
|       </buildProviders> |       </buildProviders> | ||||||
|  |  | ||||||
|  | @ -47,7 +47,7 @@ namespace FineUIPro.Web | ||||||
|             { |             { | ||||||
|                 string postData = $"code={code}&client_id={clientId}&client_secret={clientSecret}&grant_type={grant_type}&redirect_uri={redirect_url}&scope={scope}"; |                 string postData = $"code={code}&client_id={clientId}&client_secret={clientSecret}&grant_type={grant_type}&redirect_uri={redirect_url}&scope={scope}"; | ||||||
|                 //BLL.ErrLogInfo.WriteLog($"请求参数postData={postData}"); |                 //BLL.ErrLogInfo.WriteLog($"请求参数postData={postData}"); | ||||||
|                 string result = BLL.Common.HttpHelper.HttpPost(baseUrl, postData); |                 string result = BLL.Common.HttpHelper.PostJsonByHttps(baseUrl, postData); | ||||||
|                 //BLL.ErrLogInfo.WriteLog($"请求API Result={result}"); |                 //BLL.ErrLogInfo.WriteLog($"请求API Result={result}"); | ||||||
|                 var Data = JsonConvert.DeserializeObject<AccessTokenModel>(result); |                 var Data = JsonConvert.DeserializeObject<AccessTokenModel>(result); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -8,7 +8,7 @@ | ||||||
|     <IISExpressWindowsAuthentication /> |     <IISExpressWindowsAuthentication /> | ||||||
|     <IISExpressUseClassicPipelineMode /> |     <IISExpressUseClassicPipelineMode /> | ||||||
|     <UseGlobalApplicationHostFile /> |     <UseGlobalApplicationHostFile /> | ||||||
|     <LastActiveSolutionConfig>Release|Any CPU</LastActiveSolutionConfig> |     <LastActiveSolutionConfig>Debug|Any CPU</LastActiveSolutionConfig> | ||||||
|   </PropertyGroup> |   </PropertyGroup> | ||||||
|   <ProjectExtensions> |   <ProjectExtensions> | ||||||
|     <VisualStudio> |     <VisualStudio> | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue