基线 SVN r240

SVN-Revision: r240
This commit is contained in:
cyf
2025-02-06 06:46:06 +00:00
commit ab56a9bcf7
5317 changed files with 902274 additions and 0 deletions
@@ -0,0 +1,20 @@
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PostToWX", "PostToWX\PostToWX.csproj", "{30C669BC-C874-4000-A656-670350BEAFB6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{30C669BC-C874-4000-A656-670350BEAFB6}.Debug|x86.ActiveCfg = Debug|x86
{30C669BC-C874-4000-A656-670350BEAFB6}.Debug|x86.Build.0 = Debug|x86
{30C669BC-C874-4000-A656-670350BEAFB6}.Release|x86.ActiveCfg = Release|x86
{30C669BC-C874-4000-A656-670350BEAFB6}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
@@ -0,0 +1,35 @@
<GhostDoc>
<SpellChecker>
<IncludeExtensions>
</IncludeExtensions>
<IgnoreExtensions>
</IgnoreExtensions>
<IgnoreFiles>
</IgnoreFiles>
</SpellChecker>
<HelpConfigurations selected="HelpFile">
<HelpConfiguration name="HelpFile">
<OutputPath>.\Help</OutputPath>
<ImageFolderPath />
<HtmlFormats>
<HtmlHelp>true</HtmlHelp>
<MSHelpViewer>false</MSHelpViewer>
<MSHelp2>false</MSHelp2>
<Website>false</Website>
</HtmlFormats>
<IncludeScopes>
<Public>true</Public>
<Internal>false</Internal>
<Protected>false</Protected>
<Private>false</Private>
<Inherited>true</Inherited>
<EnableTags>false</EnableTags>
<TagList />
</IncludeScopes>
<ResolveCrefLinks>true</ResolveCrefLinks>
<HeaderText />
<FooterText />
<SelectedProjects />
</HelpConfiguration>
</HelpConfigurations>
</GhostDoc>
@@ -0,0 +1,267 @@
namespace PostToWX
{
partial class Form1
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.textBox1 = new System.Windows.Forms.TextBox();
this.btnRefrash = new System.Windows.Forms.Button();
this.timer2 = new System.Windows.Forms.Timer(this.components);
this.panel1 = new System.Windows.Forms.Panel();
this.label6 = new System.Windows.Forms.Label();
this.textBox6 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.txtPassword = new System.Windows.Forms.TextBox();
this.txtUser = new System.Windows.Forms.TextBox();
this.txtDBName = new System.Windows.Forms.TextBox();
this.txtServerName = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.panel2 = new System.Windows.Forms.Panel();
this.panel1.SuspendLayout();
this.panel2.SuspendLayout();
this.SuspendLayout();
//
// timer1
//
this.timer1.Interval = 30000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// textBox1
//
this.textBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.textBox1.Location = new System.Drawing.Point(0, 65);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.ReadOnly = true;
this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.textBox1.Size = new System.Drawing.Size(729, 396);
this.textBox1.TabIndex = 0;
//
// btnRefrash
//
this.btnRefrash.Location = new System.Drawing.Point(646, 36);
this.btnRefrash.Name = "btnRefrash";
this.btnRefrash.Size = new System.Drawing.Size(75, 23);
this.btnRefrash.TabIndex = 1;
this.btnRefrash.Text = "开始同步";
this.btnRefrash.UseVisualStyleBackColor = true;
this.btnRefrash.Click += new System.EventHandler(this.btnRefrash_Click);
//
// timer2
//
this.timer2.Enabled = true;
this.timer2.Interval = 3600000;
this.timer2.Tick += new System.EventHandler(this.timer2_Tick);
//
// panel1
//
this.panel1.Controls.Add(this.label6);
this.panel1.Controls.Add(this.textBox6);
this.panel1.Controls.Add(this.button1);
this.panel1.Controls.Add(this.txtPassword);
this.panel1.Controls.Add(this.txtUser);
this.panel1.Controls.Add(this.txtDBName);
this.panel1.Controls.Add(this.txtServerName);
this.panel1.Controls.Add(this.label5);
this.panel1.Controls.Add(this.label4);
this.panel1.Controls.Add(this.label3);
this.panel1.Controls.Add(this.label2);
this.panel1.Controls.Add(this.label1);
this.panel1.Controls.Add(this.btnRefrash);
this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(729, 65);
this.panel1.TabIndex = 5;
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(217, 39);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(101, 12);
this.label6.TabIndex = 14;
this.label6.Text = "分钟(最短10分钟)";
this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// textBox6
//
this.textBox6.Location = new System.Drawing.Point(94, 35);
this.textBox6.Multiline = true;
this.textBox6.Name = "textBox6";
this.textBox6.Size = new System.Drawing.Size(117, 21);
this.textBox6.TabIndex = 13;
this.textBox6.Text = "10";
this.textBox6.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.textBox6.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox6_KeyPress);
//
// button1
//
this.button1.Location = new System.Drawing.Point(646, 7);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 12;
this.button1.Text = "连接数据库";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click_1);
//
// txtPassword
//
this.txtPassword.Location = new System.Drawing.Point(548, 8);
this.txtPassword.Multiline = true;
this.txtPassword.Name = "txtPassword";
this.txtPassword.PasswordChar = '*';
this.txtPassword.Size = new System.Drawing.Size(92, 21);
this.txtPassword.TabIndex = 11;
//
// txtUser
//
this.txtUser.Location = new System.Drawing.Point(417, 8);
this.txtUser.Multiline = true;
this.txtUser.Name = "txtUser";
this.txtUser.Size = new System.Drawing.Size(92, 21);
this.txtUser.TabIndex = 10;
//
// txtDBName
//
this.txtDBName.Location = new System.Drawing.Point(275, 8);
this.txtDBName.Multiline = true;
this.txtDBName.Name = "txtDBName";
this.txtDBName.Size = new System.Drawing.Size(92, 21);
this.txtDBName.TabIndex = 8;
//
// txtServerName
//
this.txtServerName.Location = new System.Drawing.Point(94, 8);
this.txtServerName.Multiline = true;
this.txtServerName.Name = "txtServerName";
this.txtServerName.Size = new System.Drawing.Size(117, 21);
this.txtServerName.TabIndex = 7;
//
// label5
//
this.label5.Location = new System.Drawing.Point(12, 36);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(85, 17);
this.label5.TabIndex = 6;
this.label5.Text = "同步时间间隔:";
this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label4
//
this.label4.Location = new System.Drawing.Point(217, 9);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(61, 17);
this.label4.TabIndex = 5;
this.label4.Text = "数据库名:";
this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label3
//
this.label3.Location = new System.Drawing.Point(373, 9);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(47, 17);
this.label3.TabIndex = 4;
this.label3.Text = "用户名:";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label2
//
this.label2.Location = new System.Drawing.Point(515, 9);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(36, 17);
this.label2.TabIndex = 3;
this.label2.Text = "密码:";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label1
//
this.label1.Location = new System.Drawing.Point(22, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(72, 17);
this.label1.TabIndex = 2;
this.label1.Text = "数据库地址:";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// panel2
//
this.panel2.Controls.Add(this.textBox1);
this.panel2.Controls.Add(this.panel1);
this.panel2.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel2.Location = new System.Drawing.Point(0, 0);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(729, 461);
this.panel2.TabIndex = 6;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(729, 461);
this.Controls.Add(this.panel2);
this.MinimumSize = new System.Drawing.Size(745, 200);
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "同步工具";
this.Load += new System.EventHandler(this.Form1_Load);
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
this.panel2.ResumeLayout(false);
this.panel2.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button btnRefrash;
private System.Windows.Forms.Timer timer2;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.TextBox textBox6;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox txtPassword;
private System.Windows.Forms.TextBox txtUser;
private System.Windows.Forms.TextBox txtDBName;
private System.Windows.Forms.TextBox txtServerName;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label2;
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,126 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="timer2.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>107, 17</value>
</metadata>
</root>
@@ -0,0 +1,80 @@
/******************************
* 说明:Get请求
* 创建人:龚宇超
* 创建日期:2019-07-30
* 修改人:
* 修改日期:
* 修改备注:
* 版本:1.0.0.0
******************************/
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web.Script.Serialization;
namespace PostToWX
{
/// <summary>
/// Get请求
/// </summary>
public static class GetUtil
{
/// <summary>
/// <para>说明:获取Response Html</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2019-08-24 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="url">The URL.</param>
/// <returns>System.String.</returns>
public static string Get(string url)
{
return RequestUtil.HttpGet(url);
}
/// <summary>
/// <para>说明:获取JSON数据</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2019-07-30 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="url">The URL.</param>
/// <returns>T.</returns>
public static T GetJson<T>(string url)
{
string returnText = RequestUtil.HttpGet(url);
JavaScriptSerializer js = new JavaScriptSerializer();
T result = js.Deserialize<T>(returnText);
return result;
}
/// <summary>
/// <para>说明:获取JSON数据</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2019-07-30 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="url">The URL.</param>
/// <param name="header">The header.</param>
/// <returns>T.</returns>
public static T GetJson<T>(string url, WebHeaderCollection header)
{
string returnText = RequestUtil.HttpGet(url, header);
JavaScriptSerializer js = new JavaScriptSerializer();
T result = js.Deserialize<T>(returnText);
return result;
}
}
}
@@ -0,0 +1,181 @@
/******************************
* 说明:Json相关操作
* 创建人:龚宇超
* 创建日期:2017-10-23
* 修改人:
* 修改日期:
* 修改备注:
* 版本:1.0.0.0
******************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Web.Script.Serialization;
using System.Collections;
namespace PostToWX
{
/// <summary>
/// Json 相关操作
/// </summary>
public static class JsonUtil
{
/// <summary>
/// <para>说明:json 字符串转换为DataTable</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-10-23 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="json">The json.</param>
/// <returns>DataTable.</returns>
public static DataTable ToDataTable(this string json)
{
DataTable dataTable = new DataTable(); //实例化
DataTable result;
try
{
JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
javaScriptSerializer.MaxJsonLength = Int32.MaxValue; //取得最大数值
ArrayList arrayList = javaScriptSerializer.Deserialize<ArrayList>(json);
if (arrayList.Count > 0)
{
foreach (Dictionary<string, object> dictionary in arrayList)
{
if (dictionary.Keys.Count<string>() == 0)
{
result = dataTable;
return result;
}
if (dataTable.Columns.Count == 0)
{
foreach (string current in dictionary.Keys)
{
dataTable.Columns.Add(current, dictionary[current].GetType());
}
}
DataRow dataRow = dataTable.NewRow();
foreach (string current in dictionary.Keys)
{
dataRow[current] = dictionary[current];
}
dataTable.Rows.Add(dataRow); //循环添加行到DataTable中
}
}
}
catch
{
}
result = dataTable;
return result;
}
/// <summary>
/// <para>说明:</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-10-23 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="json">The json.</param>
/// <returns>DataRow.</returns>
public static DataRow ToDataRow(this string json)
{
if (string.IsNullOrWhiteSpace(json)) return null;
return ToDataTable(json).Rows[0];
}
/// <summary>
/// <para>说明:DataTable To JsonArray</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-10-23 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="dtTable">The dt table.</param>
/// <returns>System.String.</returns>
public static string ToJsonArray(this DataTable dtTable)
{
JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
javaScriptSerializer.MaxJsonLength = Int32.MaxValue; //取得最大数值
ArrayList arrayList = new ArrayList();
foreach (DataRow dataRow in dtTable.Rows)
{
Dictionary<string, object> dictionary = new Dictionary<string, object>(); //实例化一个参数集合
foreach (DataColumn dataColumn in dtTable.Columns)
{
dictionary.Add(dataColumn.ColumnName, dataRow[dataColumn.ColumnName].ToStr());
}
arrayList.Add(dictionary); //ArrayList集合中添加键值
}
return javaScriptSerializer.Serialize(arrayList); //返回一个json字符串
}
/// <summary>
/// <para>说明:DataRow To Json</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-10-23 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="row">The row.</param>
/// <returns>System.String.</returns>
public static string ToJsonObject(this DataRow row)
{
JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
javaScriptSerializer.MaxJsonLength = Int32.MaxValue; //取得最大数值
ArrayList arrayList = new ArrayList();
Dictionary<string, object> dictionary = new Dictionary<string, object>(); //实例化一个参数集合
foreach (DataColumn dataColumn in row.Table.Columns)
{
dictionary.Add(dataColumn.ColumnName, row[dataColumn.ColumnName].ToStr());
}
arrayList.Add(dictionary); //ArrayList集合中添加键值
return javaScriptSerializer.Serialize(arrayList);
}
/// <summary>
/// <para>说明:</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-10-23 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="s">The s.</param>
/// <param name="format">The format.</param>
/// <returns>A <see cref="System.String" /> that represents this instance.</returns>
public static string ToStr(this object s, string format = "")
{
string result = string.Empty;
try
{
if (string.IsNullOrWhiteSpace(format))
{
result = s.ToString();
}
else
{
result = string.Format("{0:" + format + "}", s);
}
}
catch
{
}
return result;
}
}
}
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PostToWX
{
/// <summary>
/// Request请求枚举
/// </summary>
public enum MethodEnum
{
POST,
GET,
PUT,
DELETE
}
}
@@ -0,0 +1,117 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{30C669BC-C874-4000-A656-670350BEAFB6}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>PostToWX</RootNamespace>
<AssemblyName>PostToWX</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<PlatformTarget>x86</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Lskj.Business">
<HintPath>引用dll\Lskj.Business.dll</HintPath>
</Reference>
<Reference Include="Lskj.Control">
<HintPath>引用dll\Lskj.Control.dll</HintPath>
</Reference>
<Reference Include="Lskj.Core">
<HintPath>引用dll\Lskj.Core.dll</HintPath>
</Reference>
<Reference Include="Lskj.Data">
<HintPath>引用dll\Lskj.Data.dll</HintPath>
</Reference>
<Reference Include="Lskj.Model">
<HintPath>引用dll\Lskj.Model.dll</HintPath>
</Reference>
<Reference Include="Lskj.Util">
<HintPath>引用dll\Lskj.Util.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Web">
<HintPath>bin\Debug\System.Web.dll</HintPath>
</Reference>
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="GetUtil.cs" />
<Compile Include="JsonUtil.cs" />
<Compile Include="MethodEnum.cs" />
<Compile Include="PostUtil.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RequestUtil.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include="app.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
@@ -0,0 +1,145 @@
/******************************
* 说明:Post帮助类
* 创建人:龚宇超
* 创建日期:2019-07-30
* 修改人:
* 修改日期:
* 修改备注:
* 版本:1.0.0.0
******************************/
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
using System.Web.Script.Serialization;
namespace PostToWX
{
/// <summary>
/// Post帮助类
/// </summary>
public static class PostUtil
{
/// <summary>
/// <para>说明:获取Post结果</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2019-07-30 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="returnText">The return text.</param>
/// <returns>T.</returns>
public static T GetResult<T>(string returnText)
{
JavaScriptSerializer js = new JavaScriptSerializer();
T result = js.Deserialize<T>(returnText);
return result;
}
/// <summary>
/// <para>说明:发起Post请求</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2019-07-30 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <typeparam name="T">返回数据类型(Json对应的实体)</typeparam>
/// <param name="url">请求Url</param>
/// <param name="content">The content.</param>
/// <returns>T.</returns>
public static T PostUrl<T>(string url, string content)
{
string returnText = RequestUtil.HttpPost(url, content);
var result = GetResult<T>(returnText);
return result;
}
/// <summary>
/// <para>说明:发起Post请求</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2019-07-30 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="url">The URL.</param>
/// <param name="content">The content.</param>
/// <param name="header">The header.</param>
/// <returns>T.</returns>
public static T PostUrl<T>(string url, string content, WebHeaderCollection header)
{
string returnText = RequestUtil.HttpPost(url, content, header);
var result = GetResult<T>(returnText);
return result;
}
/// <summary>
/// <para>说明:发起Post请求</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2019-07-30 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="url">The URL.</param>
/// <param name="content">The content.</param>
/// <param name="header">The header.</param>
/// <param name="method">The method.</param>
/// <returns>T.</returns>
public static T PostUrl<T>(string url, string content, WebHeaderCollection header, MethodEnum method)
{
string returnText = RequestUtil.HttpPost(url, content, header, method);
var result = GetResult<T>(returnText);
return result;
}
/// <summary>
/// <para>说明:发起Post请求</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2019-07-30 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <typeparam name="T">返回数据类型(Json对应的实体)</typeparam>
/// <param name="url">请求Url</param>
/// <param name="cookieContainer">CookieContainer,如果不需要则设为null</param>
/// <param name="fileName">要发送的文件名,如果不需要上传则设为null</param>
/// <returns>T.</returns>
public static T PostGetJson<T>(string url, CookieContainer cookieContainer, string fileName)
{
string returnText = RequestUtil.HttpPost(url, cookieContainer, fileName);
var result = GetResult<T>(returnText);
return result;
}
/// <summary>
/// <para>说明:发起Post请求</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2019-07-30 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <typeparam name="T">返回数据类型(Json对应的实体)</typeparam>
/// <param name="url">请求Url</param>
/// <param name="cookieContainer">CookieContainer,如果不需要则设为null</param>
/// <param name="fileStream">文件流</param>
/// <returns>T.</returns>
public static T PostGetJson<T>(string url, CookieContainer cookieContainer, Stream fileStream)
{
string returnText = RequestUtil.HttpPost(url, cookieContainer, fileStream);
var result = GetResult<T>(returnText);
return result;
}
}
}
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace PostToWX
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的常规信息通过以下
// 特性集控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("PostToWX")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PostToWX")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 使此程序集中的类型
// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,
// 则将该类型上的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("c07268a1-6cd4-4019-b991-80cc28588fd7")]
// 程序集的版本信息由下面四个值组成:
//
// 主版本
// 次版本
// 内部版本号
// 修订号
//
// 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值,
// 方法是按如下所示使用“*”:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,63 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace PostToWX.Properties {
using System;
/// <summary>
/// 一个强类型的资源类,用于查找本地化的字符串等。
/// </summary>
// 此类是由 StronglyTypedResourceBuilder
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
// 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
// (以 /str 作为命令选项),或重新生成 VS 项目。
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// 返回此类使用的缓存的 ResourceManager 实例。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("PostToWX.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// 使用此强类型资源类,为所有资源查找
/// 重写当前线程的 CurrentUICulture 属性。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
}
}
@@ -0,0 +1,117 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
@@ -0,0 +1,26 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace PostToWX.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
}
}
@@ -0,0 +1,7 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>
@@ -0,0 +1,284 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;
using System.Web;
namespace PostToWX
{
/// <summary>
/// Request请求帮助类
/// </summary>
public static class RequestUtil
{
/// <summary>
/// <para>说明:使用Get方法获取字符串结果(暂时没有加入Cookie</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2019-07-30 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="url">The URL.</param>
/// <returns>System.String.</returns>
public static string HttpGet(string url)
{
WebClient wc = new WebClient();
wc.Encoding = Encoding.UTF8;
return wc.DownloadString(url);
}
/// <summary>
/// <para>说明:使用Get方法获取字符串结果(暂时没有加入Cookie</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2019-07-30 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="url">The URL.</param>
/// <param name="header">The header.</param>
/// <returns>System.String.</returns>
public static string HttpGet(string url, WebHeaderCollection header)
{
WebClient wc = new WebClient();
if (header != null)
{
wc.Headers = header;
}
wc.Encoding = Encoding.UTF8;
return wc.DownloadString(url);
}
/// <summary>
/// <para>说明:使用Post方法获取字符串结果</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2019-07-30 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="url">The URL.</param>
/// <param name="cookieContainer">The cookie container.</param>
/// <param name="fileName">Name of the file.</param>
/// <returns>System.String.</returns>
public static string HttpPost(string url, CookieContainer cookieContainer, string fileName)
{
FileStream fileStream = null;
if (!string.IsNullOrEmpty(fileName) && File.Exists(fileName))
{
//读取文件
fileStream = new FileStream(fileName, FileMode.Open);
}
return HttpPost(url, cookieContainer, fileStream);
}
/// <summary>
/// <para>说明:使用Post方法获取字符串结果</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2019-07-30 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="url">The URL.</param>
/// <param name="content">The content.</param>
/// <param name="timeout">The timeout.</param>
/// <returns>System.String.</returns>
public static string HttpPost(string url, string content, int timeout = 5000)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ServicePoint.Expect100Continue = false;
request.ContentType = "application/json;charset=utf8";
request.Timeout = timeout;
byte[] buffer = Encoding.UTF8.GetBytes(content);
request.ContentLength = buffer.Length;
request.GetRequestStream().Write(buffer, 0, buffer.Length);
HttpWebResponse response = null;
try
{
response = (HttpWebResponse)request.GetResponse();
}
catch (WebException ex)
{
response = (HttpWebResponse)ex.Response;
Console.WriteLine(ex.Message);
return "";
}
using (Stream responseStream = response.GetResponseStream())
{
using (StreamReader myStreamReader = new StreamReader(responseStream, Encoding.GetEncoding("utf-8")))
{
string retString = myStreamReader.ReadToEnd();
return retString;
}
}
}
/// <summary>
/// <para>说明:使用Post方法获取字符串结果</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2019-07-30 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="url">The URL.</param>
/// <param name="content">The content.</param>
/// <param name="header">The header.</param>
/// <returns>System.String.</returns>
public static string HttpPost(string url, string content, WebHeaderCollection header)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
if (header != null)
{
request.Headers = header;
}
request.ServicePoint.Expect100Continue = false;
request.ContentType = "application/json;charset=utf8";
byte[] buffer = Encoding.UTF8.GetBytes(content);
request.ContentLength = buffer.Length;
request.GetRequestStream().Write(buffer, 0, buffer.Length);
HttpWebResponse response = null;
try
{
response = (HttpWebResponse)request.GetResponse();
}
catch (WebException ex)
{
response = (HttpWebResponse)ex.Response;
Console.WriteLine(ex.Message);
return "";
}
using (Stream responseStream = response.GetResponseStream())
{
using (StreamReader myStreamReader = new StreamReader(responseStream, Encoding.GetEncoding("utf-8")))
{
string retString = myStreamReader.ReadToEnd();
return retString;
}
}
}
/// <summary>
/// <para>说明:使用Post方法获取字符串结果</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2019-07-30 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="url">The URL.</param>
/// <param name="content">The content.</param>
/// <param name="header">The header.</param>
/// <param name="method">The method.</param>
/// <returns>System.String.</returns>
public static string HttpPost(string url, string content, WebHeaderCollection header, MethodEnum method)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = method.ToString();
if (header != null)
{
request.Headers = header;
}
request.ServicePoint.Expect100Continue = false;
request.ContentType = "application/json;charset=utf8";
byte[] buffer = Encoding.UTF8.GetBytes(content);
request.ContentLength = buffer.Length;
request.GetRequestStream().Write(buffer, 0, buffer.Length);
HttpWebResponse response = null;
try
{
response = (HttpWebResponse)request.GetResponse();
}
catch (WebException ex)
{
response = (HttpWebResponse)ex.Response;
Console.WriteLine(ex.Message);
return "";
}
using (Stream responseStream = response.GetResponseStream())
{
using (StreamReader myStreamReader = new StreamReader(responseStream, Encoding.GetEncoding("utf-8")))
{
string retString = myStreamReader.ReadToEnd();
return retString;
}
}
}
/// <summary>
/// <para>说明:使用Post方法获取字符串结果</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2019-07-30 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="url">The URL.</param>
/// <param name="cookieContainer">The cookie container.</param>
/// <param name="fileStream">The file stream.</param>
/// <returns>System.String.</returns>
public static string HttpPost(string url, CookieContainer cookieContainer, Stream fileStream)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
//request.ContentType = "application/x-www-form-urlencoded";
request.ContentType = "application/json;charset=utf8";
request.ContentLength = fileStream != null ? fileStream.Length : 0;
if (cookieContainer != null)
{
request.CookieContainer = cookieContainer;
}
if (fileStream != null)
{
Stream requestStream = request.GetRequestStream();
byte[] buffer = new byte[1024];
int bytesRead = 0;
while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
{
requestStream.Write(buffer, 0, bytesRead);
}
fileStream.Close();//关闭文件访问
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (cookieContainer != null)
{
response.Cookies = cookieContainer.GetCookies(response.ResponseUri);
}
using (Stream responseStream = response.GetResponseStream())
{
using (StreamReader myStreamReader = new StreamReader(responseStream, Encoding.GetEncoding("utf-8")))
{
string retString = myStreamReader.ReadToEnd();
return retString;
}
}
}
/// <summary>
/// <para>说明:请求是否发起自客户端的浏览器</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2019-07-30 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="httpContext">The HTTP context.</param>
/// <returns><c>true</c> if [is sogou client request] [the specified HTTP context]; otherwise, <c>false</c>.</returns>
public static bool IsSogouClientRequest(HttpContext httpContext)
{
return !string.IsNullOrEmpty(httpContext.Request.UserAgent) &&
httpContext.Request.UserAgent.Contains("MicroMessenger");
}
}
}
@@ -0,0 +1,3 @@
<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>