谁哪里有例子呢?比如人人网的....天涯论坛的等等,希望有的能给我发一份,一定要能用呀,从网上找了几个,都不行!
发了的,记着在下面留言,直接给分!200
发了的,记着在下面留言,直接给分!200
解决方案 »
- 紧急!!:C#如何用listview管理多个同名外部程序的运行和停止
- C# 用代码实现删除引用
- 求一个简单的正则表达式。第一个匹对者则给满分。
- 如何让用户认证后才可以下载文件(网站的方式)?
- 根据XML配置文件建立数据库的连接
- 统一登陆的问题,UP有分。
- web下调用windows form应用程序
- System.Data.SqlClient.SqlException: 用户 'XIELIN\ASPNET' 登录失败。
- (一个简单的问题,急,谢谢)new 一个类的数组,怎么做?
- 装vs.net一定要windows 2000 server吗,装windows 2000 professional行吗
- C# 把十六进制转成字符串
- Grid++Report表达式
public string Login(String url, String paramList)
{
HttpWebResponse res = null;
string strResult = "";
string postdata = null; try
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
//req.AllowAutoRedirect = false;
req.AllowWriteStreamBuffering = false;//禁用数据缓存
//if (myCookieContainer!=null)
//{
req.CookieContainer = myCookieContainer;
//}
//req.Connection = "keep - alive";
postdata = bianma(paramList); byte[] data = Encoding.GetEncoding(charset).GetBytes(postdata);
req.ContentLength = data.Length;
Stream strm = req.GetRequestStream();
strm.Write(data, 0, data.Length); //写入参数
strm.Close();
res = (HttpWebResponse)req.GetResponse();
res.Cookies = myCookieContainer.GetCookies(req.RequestUri);
//myCookieContainer.Add(res.Cookies);
Stream ReceiveStream = res.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding(charset);
StreamReader sr = new StreamReader(ReceiveStream, encode); strResult = sr.ReadToEnd();
}
catch (Exception e)
{
strResult = e.ToString();
}
finally
{
if (res != null)
{
res.Close();
}
}
return strResult;
}
/// <summary>
//对参数字符串进行URL编码
/// </summary>
public string bianma(string postData)//对参数字符串进行URL编码
{
Encoding e1 = Encoding.GetEncoding(charset);
int i = 0, j;
StringBuilder UrlEncoded = new StringBuilder();
Char[] reserved = { '?', '=', '&' };
while (i < postData.Length)
{
j = postData.IndexOfAny(reserved, i);//报告指定 Unicode 字符数组中的任意字符在此实例中第一个匹配项的索引。该搜索从指定字符位置开始。
//j = 0 j=11
if (j == -1)
{
UrlEncoded.Append(HttpUtility.UrlEncode(postData.Substring(i, postData.Length - i), e1));
break;
}
UrlEncoded.Append(HttpUtility.UrlEncode(postData.Substring(i, j - i), e1));
//在此实例的结尾追加指定对象的字符串表示形式
//HttpUtility提供用于在处理 Web 请求时编码和解码 URL 的方法。
//UrlEncode()方法对 URL 字符串进行编码。
//Append函数在此实例的结尾追加指定数组的Unicode字符的字符串表示形式
UrlEncoded.Append(postData.Substring(j, 1));
i = j + 1;
}
// Encoding.Unicode.GetString(UrlEncoded);
return UrlEncoded.ToString(); }