能实现这个功能吗?
在客户打开我网页的同时,可否让客户端向第三方站点“GET”或“POST”数据?
没学过asp.net,不知道用 "HttpWebRequest "行不行?
[解决办法]
ajax xmlhttprequest
[解决办法]
只有顶的份
[解决办法]
行
HttpWebRequest myReq = (HttpWebRequest)HttpWebRequest.Create(a_strUrl);
myReq.Timeout = timeout;
HttpWebResponse HttpWResp = (HttpWebResponse)myReq.GetResponse();
Stream myStream = HttpWResp.GetResponseStream();
StreamReader sr = new StreamReader(myStream, Encoding.Default);
StringBuilder strBuilder = new StringBuilder();
[解决办法]
不错
[解决办法]
private HttpWebRequest CreateRequest()
{
if(this.URL== " ")
{
throw new Exception( "请求URL不能为空 ");
}
HttpWebRequest request = null;
try
{
request = (HttpWebRequest)HttpWebRequest.Create(this.URL);
}
catch(Exception ex)
{
throw new Exception( "出错,URL: "+this.URL,ex);
}
request.AllowAutoRedirect = false;
request.Accept = "*/* ";
request.UserAgent= "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; WinFX RunTime 3.0.50727) ";
request.CookieContainer = new CookieContainer();
request.Referer=this.RefURL;
request.Timeout = m_TimeOut;
if(this.CookiePost != null)
{
System.Uri uri = new Uri(this.URL);
foreach(System.Net.Cookie ck in this.CookiePost)
{
ck.Domain = uri.Host;
ck.Path =@ "/ ";
}
request.CookieContainer.Add(this.CookiePost);
}
if(this.PostData !=null && this.PostData.Length > 0)
{
request.ContentType = "application/x-www-form-urlencoded ";
request.Method = "POST ";
byte[] buff = this.MyEncoding.GetBytes(this.PostData);
request.ContentLength = buff.Length;
System.IO.Stream sw = null;
try
{
sw = request.GetRequestStream();
sw.Write(buff,0,buff.Length);
}
catch(Exception ex)
{
this.Err = ex.Message;
}
finally
{
if(sw != null)
{
sw.Close();
}
}
}
return request;
}
HttpWebRequest request = null;
HttpWebResponse response = null;
System.IO.StreamReader sr =null;
try
{
request = this.CreateRequest();
response = (HttpWebResponse)request.GetResponse();
sr = new System.IO.StreamReader(response.GetResponseStream(),this.MyEncoding);
this.ReturnHtml = sr.ReadToEnd();
this.m_Succeed=true;
this.ReturnCode = response.StatusCode.ToString();
}