如题。100送上。
解决方案 »
- 如何根据DLL文件来加载菜单项
- socket接收数据时没有接收完,如何继续接受
- 想在Remoting中实现在线用户统计,如何实现?
- 程序中如何设置DataGrid的某一行(比如第5行)的背景色根HeadText的背景色一致?
- 制作安装程序怎样在"开始->程序"中做出"卸载"功能
- 紧急求助!两个不同panel中互相拖动各自内的picturebox到另一panel
- .NET 导入Excel表提示“外部表不是预期的格式”,然而如果新建一个Excel文件导入则不会报错
- Singleton模式在C#中如何实现,请给我一个例子?
- 关于listbox和textbox的问题
- button 怎么响应回车
- 推荐几款C#建模工具给大家!
- 关于扫描枪的问题
tmpurl="请求URL信息";
System.Net.WebClient wc=new WebClient();
System.IO.StreamReader sr=new System.IO.StreamReader( wc.OpenRead(tmpurl),encode);
tmpurl="";
tmpurl=sr.ReadToEnd();
tmpurl即取得返回所有信息
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://abc.com.cn/xyz.aspx");
//构造要post的数据
ASCIIEncoding encoding=new ASCIIEncoding();
string postdata="a=xxx&b=xxx";
byte[] byte1=encoding.GetBytes(postdata);
//Post
req.Method = "POST";
req.ContentType="application/x-www-form-urlencoded";
req.ContentLength=postdata.Length;
Stream s=req.GetRequestStream();
s.Write(byte1,0,byte1.Length);
s.Close();
//获取响应
HttpWebResponse rp= (HttpWebResponse)req.GetResponse();
Stream rps= rp.GetResponseStream();
StreamReader sr= new StreamReader(rps);
//获得响应字符串
string result = sr.ReadToEnd();
rp.Close();
{
//建立登录检查地址
string url = @"http://howaa.baoyaa.com/smslt.asp";
//建立request对象
System.Net.HttpWebRequest req=(System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(url);
//这个新建的Cookie集合不知道有什么用??
//req.CookieContainer =new CookieContainer ();
req.Method="POST";//POST方式请求
req.ContentType= "application/x-www-form-urlencoded";//内容类型
//参数经过URL编码
string paraUrlCoded;
paraUrlCoded=System.Web.HttpUtility.UrlEncode("MobilePhone") +"="+System.Web.HttpUtility.UrlEncode("13564250347");
// paraUrlCoded+="&";
// paraUrlCoded+=System.Web.HttpUtility.UrlEncode("passwd")+"="+System.Web.HttpUtility.UrlEncode("999999"); //将URL编码后的字符串转化为字节
try
{
byte[] payload;
payload=System.Text.Encoding.UTF8.GetBytes(paraUrlCoded);
req.ContentLength=payload.Length; //设置请求的ContentLength
System.IO.Stream writer=req.GetRequestStream();//获得请求流
writer.Write(payload,0,payload.Length);//将请求参数写入流
writer.Close();//关闭请求流
}
catch
{} //获得响应流
}
/// <summary>
/// Get数据类
/// </summary>
public class GetDate
{
private string sPostUrl;
/// <summary>
/// 提交地址
/// </summary>
public string postUrl
{
get
{
return sPostUrl;
}
set
{
sPostUrl=value;
}
}
private CookieContainer sSessionId;
/// <summary>
/// Cookies标志
/// </summary>
public CookieContainer SessionId
{
get
{
return sSessionId;
}
set
{
sSessionId=value;
}
}
private string sReturnString;
/// <summary>
/// 返回字符串
/// </summary>
/// <returns></returns>
public string ReturnString
{
get
{
return sReturnString;
}
set
{
sReturnString=value;
}
} public void Send()
{
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(sPostUrl);
request.CookieContainer=sSessionId;
request.Method="get";
//request.Timeout=2240;
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
byte[] buf = new byte[1024];
int count=0;
while(true)
{
//resStream.Write(byte1,0,byte1.Length);
count = response.GetResponseStream().Read(buf, 0, buf.Length);
if (count<=0)
{
break;
}
sReturnString+=Encoding.Unicode.GetString(buf,0,count);
}
}
} #endregion
//req.CookieContainer =new CookieContainer ();
=================================================
如果需要在请求之间保存Session状态,就有用了