HttpWebRequest的异步问题
兄弟我做一个把IP转化为相应地址的程序。现在想做到异步功能,可是不知道如何处理,下面是我的代码,请问在什么地方修改变成异步呢。
我现在的代码是给了一个定的IP,因为我以后,要进行从数据库里,提取大量IP进行转化。所以要采用异步。下面是我的程序
我现在的代码是给了一个定的IP,因为我以后,要进行从数据库里,提取大量IP进行转化。所以要采用异步。下面是我的程序
string strIP = this.txtIP.Text.Trim();
string strAction = "2";
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "ip=" + strIP;
postData += "&action=" + strAction;
byte[] data = encoding.GetBytes(postData);
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://www.ip138.com/ips.asp");
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
Stream myStream = myRequest.GetRequestStream();
myStream.Write(data, 0, data.Length);
myStream.Close();
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.Default);
string content = reader.ReadToEnd();
string con = content.Substring(content.IndexOf("本站主数据") + 6, content.IndexOf("</li><li>参考数据一") - content.IndexOf("本站主数据") - 1);
this.lblViewIP.Text = con;
...全文
相关推荐
wphone WebClient和HttpWebRequest
window phone WebClient和HttpWebRequest 并解决gb2312乱码问题
C# HttpWebRequest断点续传
1、启动和暂停下载 2、展示下载进度
httpwebrequest工具类
httpwebrequest工具类 可以有来抓取网面 代码从网上获取
unity-HttpWebRequest下载
unity-HttpWebRequest下载,支持断点续传,支持临时文件,ios、安卓支持
HttpWebRequest爬虫
利用HttpWebRequest简单爬虫,url可以自定义。是基本的读取网页内容,提取信息,只适合初学者。



