资源简介
一个小工具模仿发送http的get、post方式请求。
代码片段和文件信息
////////////////////////////////////////////////////////////
// FrmTestHttpPost.cs: 测试Http的POST方法.
// Author: zyl910
// Blog: http://www.cnblogs.com/zyl910
// URL: http://www.cnblogs.com/zyl910/archive/2012/09/19/TestHttpPost.html
// Version: V1.00
// Updata: 2012-09-19
//
////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
using System.Net.Cache;
namespace TestHttpPost
{
public partial class FrmTestHttpPost : Form
{
private EncodingInfo[] _Encodings = null; // 编码集合.
private Encoding _ResEncoding = null; // 回应的编码.
public FrmTestHttpPost()
{
InitializeComponent();
}
///
/// 根据BodyName创建Encoding对象。
///
/// 与邮件代理正文标记一起使用的当前编码的名称。
/// 返回Encoding对象。若没有匹配的BodyName,便返回null。
public static Encoding Encoding_FromBodyName(string bodyname)
{
if (string.IsNullOrEmpty(bodyname)) return null;
try
{
foreach (EncodingInfo ei in Encoding.GetEncodings())
{
Encoding e = ei.GetEncoding();
if (0 == string.Compare(bodyname e.BodyName true))
{
return e;
}
}
}
catch
{
}
return null;
}
///
/// 输出日志文本.
///
/// 日志文本
private void OutLog(string s)
{
txtLog.AppendText(s + Environment.NewLine);
txtLog.ScrollToCaret();
}
private void OutLog(string format params object[] args)
{
OutLog(string.Format(format args));
}
private void FrmTestHttpPost_Load(object sender EventArgs e)
{
// Http方法
cboMode.SelectedIndex = 1; // POST
// 回应的编码
cboResEncoding.Items.Clear();
_Encodings = Encoding.GetEncodings();
cboResEncoding.DataSource = _Encodings;
cboResEncoding.DisplayMember = “DisplayName“;
_ResEncoding = Encoding.UTF8;
cboResEncoding.SelectedIndex = cboResEncoding.FindStringExact(_ResEncoding.EncodingName);
}
private void btnGo_Click(object sender EventArgs e)
{
//httpConn.setRequestProperty(“Content-length“ ““ + data.length);
//httpConn.setRequestProperty(“Content-Type““application/octet-stream“);
//httpConn.setRequestProperty(“Connection“ “Keep-Alive“);
//httpConn.setRequestProperty(“Charset“ “UTF-8“);
Encoding myEncoding = Encoding.UTF8;
string sMode = (string)cboMode.SelectedItem;
string sUrl = txtUrl.Text;
string sPostData = txtPostData.Text;
string sContentType = “application/octet-stream“;
HttpWebRequest req;
// Log Length
if (txtLog.Lines.Length > 3000) txtLog.Clear();
// == main ==
OutLog(string.Format(“{2}: {0} {1}“ sMode sUrl DateTime.Now.ToString(“g“)));
try
{
// init
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 5574 2012-09-19 23:52 TestHttpPost\Backup\FrmTestHttpPost.cs
文件 7076 2012-09-19 23:43 TestHttpPost\Backup\FrmTestHttpPost.Designer.cs
文件 7580 2012-09-19 23:43 TestHttpPost\Backup\FrmTestHttpPost.resx
文件 403 2012-09-19 14:11 TestHttpPost\Backup\Program.cs
文件 1218 2012-09-19 23:40 TestHttpPost\Backup\Properties\AssemblyInfo.cs
文件 2532 2012-09-19 14:11 TestHttpPost\Backup\Properties\Resources.Designer.cs
文件 5350 2012-09-19 14:11 TestHttpPost\Backup\Properties\Resources.resx
文件 1019 2012-09-19 14:11 TestHttpPost\Backup\Properties\Settings.Designer.cs
文件 249 2012-09-19 14:11 TestHttpPost\Backup\Properties\Settings.settings
文件 3281 2012-09-19 23:31 TestHttpPost\Backup\TestHttpPost.csproj
文件 912 2012-09-19 14:11 TestHttpPost\Backup\TestHttpPost.sln
文件 26112 2012-10-25 15:59 TestHttpPost\bin\Debug\TestHttpPost.pdb
文件 14328 2012-10-25 15:59 TestHttpPost\bin\Debug\TestHttpPost.vshost.exe
文件 490 2009-06-11 05:14 TestHttpPost\bin\Debug\TestHttpPost.vshost.exe.manifest
文件 6401 2012-10-25 15:59 TestHttpPost\FrmTestHttpPost.cs
文件 9233 2012-10-25 15:59 TestHttpPost\FrmTestHttpPost.Designer.cs
文件 5814 2012-10-25 15:59 TestHttpPost\FrmTestHttpPost.resx
文件 4608 2012-10-23 10:32 TestHttpPost\obj\Debug\TempPE\Properties.Resources.Designer.cs.dll
文件 553 2012-10-25 15:59 TestHttpPost\obj\Debug\TestHttpPost.csproj.FileListAbsolute.txt
文件 857 2012-10-25 15:59 TestHttpPost\obj\Debug\TestHttpPost.csproj.GenerateResource.Cache
文件 15872 2012-10-25 15:59 TestHttpPost\obj\Debug\TestHttpPost.exe
文件 180 2012-10-25 15:59 TestHttpPost\obj\Debug\TestHttpPost.FrmTestHttpPost.resources
文件 26112 2012-10-25 15:59 TestHttpPost\obj\Debug\TestHttpPost.pdb
文件 180 2012-10-23 11:34 TestHttpPost\obj\Debug\TestHttpPost.Properties.Resources.resources
文件 403 2012-09-19 14:11 TestHttpPost\Program.cs
文件 1218 2012-09-19 23:40 TestHttpPost\Properties\AssemblyInfo.cs
文件 2851 2012-10-23 08:51 TestHttpPost\Properties\Resources.Designer.cs
文件 5350 2012-09-19 14:11 TestHttpPost\Properties\Resources.resx
文件 1093 2012-10-23 08:51 TestHttpPost\Properties\Settings.Designer.cs
文件 249 2012-09-19 14:11 TestHttpPost\Properties\Settings.settings
............此处省略28个文件信息
- 上一篇:ghost 远控
- 下一篇:基于SDRAM建立FIFO
评论
共有 条评论