如何发出HttpRequest对象
我这里定义了一个string为userinput(是一个URL) 之后创建了一个HttpRequest对象HttpRequest hrequest = new HttpRequest(null, userinput,null);
这里我不懂怎么把这个HttpRequest 对象发送出去。希望能得到各位大侠的帮助。
还有一个问题是我发送出去之后怎么接受他的HttpResponse对象。 想在一个DiV中显示这个请求的页面信息(Response.ContentType=text类型的就显示他)。
string userinput = TextBoxUserInput.Text;
HttpRequest hrequest = new HttpRequest(null, userinput,null);
??我如何发送出去 同时得到他的Response
string ct=Response.ContentType;
if (ct.Substring(0, 4) == "text")
{
??显示在页面的一个DIV中
} --------------------编程问答-------------------- HttpWebRequest通过post等提交到相关页面,获取执行的页面数据
private string HttpWebRequestLogin(string loginUrl, string postData, ref CookieContainer cookieContainer)
{
byte[] bdata = Encoding.Default.GetBytes(postData);
System.Net.HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(loginUrl);
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
myRequest.Referer = loginUrl;
myRequest.KeepAlive = true;
myRequest.AllowAutoRedirect = true;
if (cookieContainer == null)
cookieContainer = new CookieContainer();
myRequest.CookieContainer = cookieContainer;
myRequest.ContentLength = bdata.Length;
Stream newStream = myRequest.GetRequestStream();
newStream.Write(l_data, 0, bdata.Length);
newStream.Close();
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.GetEncoding("GB2312"));
string content = reader.ReadToEnd();
return content;
}
补充:.NET技术 , ASP.NET