C#调用winhttp组件 POST登录迅雷

下面是封装好的winhttp类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Thunder
{
/// <summary>
/// COM对象的后期绑定调用类库
/// </summary>
public class ComObject
{
private System.Type _ObjType;
private object ComInstance;
/*public DxComObject()
{
throw new
}*/
public ComObject(string ComName)
{
//根据COM对象的名称创建COM对象
_ObjType = System.Type.GetTypeFromProgID(ComName);
if (_ObjType == null)
throw new Exception("指定的COM对象名称无效");
ComInstance = System.Activator.CreateInstance(_ObjType);
}
public System.Type ComType
{
get { return _ObjType; }
}
//执行的函数
public object DoMethod(string MethodName, object[] args)
{
return ComType.InvokeMember(MethodName, System.Reflection.BindingFlags.InvokeMethod, null, ComInstance, args);
}
public object DoMethod(string MethodName, object[] args, System.Reflection.ParameterModifier[] ParamMods)
{
return ComType.InvokeMember(MethodName, System.Reflection.BindingFlags.InvokeMethod, null, ComInstance, args, ParamMods, null, null);
}
//获得属性与设置属性
public object this[string propName]
{
get
{
return _ObjType.InvokeMember(propName, System.Reflection.BindingFlags.GetProperty, null, ComInstance, null);
}
set
{
_ObjType.InvokeMember(propName, System.Reflection.BindingFlags.SetProperty, null, ComInstance, new object[] { value });
}
}
}
/// <summary>
/// WinHttp对象库
/// </summary>
public class WinHttp
{
private ComObject HttpObj;
private string _ContentType;
private int _ContentLength;
private bool _Active;
private System.Collections.ArrayList PostDataList;//提交的数据字段
public WinHttp()
{
//构建WinHttp对象
HttpObj = new ComObject("WinHttp.WinHttpRequest.5.1");
_ContentType = "application/x-www-form-urlencoded";
_ContentLength = ;
PostDataList = new System.Collections.ArrayList();
}
//提交参数信息的个数
public int PostDataCount
{
get{return PostDataList.Count;}
}
//设置Content-Type属性
public string ContentType
{
get{return _ContentType;}
set
{
if(!_Active) _ContentType = value;
)
{
_ContentType = value;
SetRequestHeader("Content-Type",_ContentType);
}
}
}
//对象是否是打开状态
public bool Active
{
get{return _Active;}
}
//设置Send数据的长度
public int ContentLength
{
get{return _ContentLength;}
set
{
if(!_Active) _ContentLength = value;
else if(_ContentLength != value)
{
_ContentLength = value;
HttpObj.DoMethod(]{"Content-Length",value});
}
}
}
//执行之后返回的结果
public string ResponseBody
{
get
{
if(_Active)
{
ComObject AdoStream = new ComObject("Adodb.Stream");
AdoStream[;
AdoStream[;
AdoStream.DoMethod("Open",new object[]{});
AdoStream.DoMethod(]{HttpObj["ResponseBody"]});
AdoStream[;
AdoStream[;
AdoStream["Charset"] = "GB2312";
return AdoStream["ReadText"].ToString();
}
else return "";
}
}
//设定请求头
public string SetRequestHeader(string Header,object Value)
{
object obj;
obj = HttpObj.DoMethod("SetRequestHeader",new object[]{Header,Value});
if(obj != null) return obj.ToString();
else return "True";
}
//打开URL执行OpenMethod方法,Async指定是否采用异步方式调用,异步方式不会阻塞
public string Open(string OpenMethod,string URL,bool Async)
{
object obj;
obj = HttpObj.DoMethod("Open",new object[]{OpenMethod,URL,Async});
if (obj != null)
{
_Active = false;
return obj.ToString();
}
else
{
SetRequestHeader("Content-Type",_ContentType);
SetRequestHeader("User-Agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
) SetRequestHeader("Content-Length",_ContentLength);
_Active = true;
return "True";
}
}
//发送数据
public string Send(string body)
{
if(!_Active) return "False";
object obj;
obj = HttpObj.DoMethod(]{body});
if(obj != null) return obj.ToString();
else return "True";
}
//清空提交信息
public void ClearPostData()
{
this.PostDataList.Clear();
}
//增加提交数据信息
public void AddPostField(string FieldName,object Value)
{
this.PostDataList.Add(FieldName+"="+Value.ToString());
}
//通过参数指定提交
public string Post()
{
if(!_Active)
{
return "False";
}
string st="";
;i<this.PostDataList.Count;i++)
{
if(st != "") st = st + "&"+ PostDataList[i].ToString();
else st = PostDataList[i].ToString();
}
this.ContentLength = st.Length;
return Send(st);
}
//设置等待超时等
public string SetTimeouts(long ResolveTimeout,long ConnectTimeout,long SendTimeout,long ReceiveTimeout)
{
object obj;
obj = HttpObj.DoMethod(]{ResolveTimeout,ConnectTimeout,SendTimeout,ReceiveTimeout});
if(obj != null) return obj.ToString();
else return "True";
}
//等待数据提交完成
public string WaitForResponse(object Timeout,out bool Succeeded)
{
if(!_Active) {Succeeded = false;return "";}
object obj;
bool succ;
succ = false;
System.Reflection.ParameterModifier[] ParamesM;
ParamesM = ];
ParamesM[] = ); // 初始化为接口参数的个数
ParamesM[][] = true; // 设置第二个参数为返回参数
//ParamesM[1] = true;
]{Timeout,succ};
obj = HttpObj.DoMethod("WaitForResponse",ParamArray,ParamesM);
System.Windows.Forms.MessageBox.Show(ParamArray[].ToString());
Succeeded=].ToString());
//Succeeded = bool.Parse(ParamArray[1].ToString);
if(obj != null) {return obj.ToString();}
else return "True";
}
public string GetResponseHeader(string Header,ref string Value)
{
if(!_Active) {Value="";return "";}
object obj;
/*string str;
str = "";
System.Reflection.ParameterModifier[] Parames;
Parames = new System.Reflection.ParameterModifier[1];
Parames[0] = new System.Reflection.ParameterModifier (2); // 初始化为接口参数的个数
Parames[0][1] = true; */// 设置第二个参数为返回参数
obj = HttpObj.DoMethod(]{Header,Value});
//Value = str;
if(obj != null) {return obj.ToString();}
else return "True";
}
public string GetAllResponseHeaders()
{
object obj;
obj =HttpObj["GetAllResponseHeaders"];
if (obj != null) { return obj.ToString(); }
else return "True";
}
}
}
C#调用winhttp组件 POST登录迅雷的更多相关文章
- php实现ppt转图片,php调用com组件问题
PHP 调用com组件将ppt转为图片. 需要在php.ini中开启 extension=php_com_dotnet.dllcom.allow_dcom = true 测试代码如下: < ...
- Titanium中调用ios组件时语言不是本地化的解决方法
用Titanium开发的ios应用中,当调用系统组件时,尽管手机已经设置了系统语言为中文,但那些组件的界面却仍为英文.比如调用iphone中的相册组件,其界面为: 那么怎么让它跟系统语言保持一致呢? ...
- VS2010调用Com组件
Com组件开发过程中用的不多,资料也不多,故记录开发Com组件中的部分问题. 在这一篇文章里,讲解了如何使用VS2010创建Com组件.现在基于该文章创建的Com组件接口,创建VC++项目来调用该接口 ...
- VC中调用COM组件的方法(转载)
原文参考:http://hi.baidu.com/mingyueye/item/53ebecd44da76917d80e4449 总结一下在VC中调用COM组件的方法 准备及条件: COM服务器为进程 ...
- .NET通过调用Office组件导出Word文档
.NET通过调用Office组件导出Word文档 最近做项目需要实现一个客户端下载word表格的功能,该功能是用户点击"下载表格",服务端将该用户的数据查询出来并生成数据到Word ...
- 服务器端调用Word组件读取Word权限、未将对象引用到对象实例终极解决方案
最近因为业务需要,需要在服务器上调用Word组件,结果遇到各种问题,比如检索 COM 类工厂中 CLSID 为 {000209FF-0000-0000-C000-000000000046} 的组件失败 ...
- vc中调用Com组件的方法详解
vc中调用Com组件的方法详解 转载自:网络,来源未知,如有知晓者请告知我.需求:1.创建myCom.dll,该COM只有一个组件,两个接口: IGetRes--方法Hello(), IGet ...
- 三界商城 ajax调用城市接口,竟然需要登录,调用的接口需要登录,如果不登录 重定向到登录
现象 商家入驻 填写信息的 ajax请求没有数据 network->name-headers 返回302 发现调用的接口,需要登录,否则重定向登录 //初始化用户信息查询 public func ...
- Asp.Net调用Office组件操作时的DCOM配置 (转)
Asp.Net调用Office组件操作时的DCOM配置 http://blog.csdn.net/gz775/article/details/6447758 在项目中将数据导出为Excel格式时出现“ ...
随机推荐
- 一键部署mono 免费空间
一键部署mono 免费空间支持c# 再也不担心伙食费换空间了 一直以来 部署mono 都是很头疼的事情 因为是我在是不熟悉非win环境,今天偶然发现这个项目,挺好的,分享下 https://githu ...
- SZU:B47 Big Integer II
Judge Info Memory Limit: 32768KB Case Time Limit: 10000MS Time Limit: 10000MS Judger: Normal Descrip ...
- C#中利用JQuery实现视频网站
C#中利用JQuery实现视频网站的缩略图采集 最近有朋友想要采集优酷的视频标题和缩略图 (哈哈, 并非商业目的). 找到我帮忙, 考虑到有我刚刚发布的SpiderStudio, 我毫不犹豫的答应 ...
- get 新技能
找usaco各种月赛的数据戳这里:ace.delos.com/NOV06 这里表2006.11的数据,其余的数据同上搜索 月赛题目http://pan.baidu.com/share/link?sha ...
- ResolveUrl in ASP.NET - The Perfect Solution
原文:ResolveUrl in ASP.NET - The Perfect Solution If you are looking for ResolveUrl outside of Page/Co ...
- 优化算法-BFGS
优化算法-BFGS BGFS是一种准牛顿算法, 所谓的"准"是指牛顿算法会使用Hessian矩阵来进行优化, 但是直接计算Hessian矩阵比较麻烦, 所以很多算法会使用近似的He ...
- JavaScript事件的几个细节
JavaScript事件的几个细节 一.是捕获还是冒泡 昨天被问到一个问题:事件流有几个阶段?在这几个阶段中,事件一共发生几次? 问题很简单,但对于事件一共发生几次有点乱.总觉得捕获也能触发事件.冒泡 ...
- 求字符串长度 strlen(数组指针两种方式)
问题: 求字符串中所含有字符的个数(包括空格),即求字符串长度: #include <stdio.h> #include <assert.h> int _strlen(cons ...
- svn签出单个文件
) { return new string[]{ string.Format("cd /d \"{0}\"",System.IO.Path.GetDirecto ...
- 跨站脚本攻击(Cross‐Site Scripting (XSS))
跨站脚本攻击(Cross‐Site Scripting (XSS)) 跨站脚本攻击(Cross‐Site Scripting (XSS)) XSS(Cross Site Script)跨站脚本攻击.是 ...