|
我想将asp写的一XMLHTTP改写为有asp.net的HttpWebRequest:
strURL="http://www.website-export.com/cgi-bin/cnps.cgi?"&cnpsStr
Set WinHttpReq = server.CreateObject("Microsoft.XMLHTTP")
WinHttpReq.Open "GET", strURL, false
WinHttpReq.SetRequestHeader "REMOTE_HOST", Request.ServerVariables("SERVER_NAME")
WinHttpReq.SetRequestHeader "URL", Request.ServerVariables("URL")
WinHttpReq.Send
strResult = WinHttpReq.ResponseText
PostCnpsRequest = strResult
改为:
Encoding encoding = Encoding.GetEncoding("GB2312");
string postData="user_id="+"1485";
postData += ("&origin_zip="+"100071");
postData+=("&desti_zip="+desti_zip);
postData+=("&shipping_weight="+shipping_weight);
postData+=("&shipping_method="+"parcel_post");
string strUrl = "http://www.website-export.com/cgi-bin/cnps.cgi";
byte[] data = encoding.GetBytes(postData);
// 准备请求...
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(strUrl);
myRequest.Method = "POST";
myRequest.ContentType="www.car8848.cn/ProductPSFS.aspx";
myRequest.ContentLength = data.Length;
Stream newStream=myRequest.GetRequestStream();
newStream.Write(data,0,data.Length);
newStream.Close();
WebResponse response = myRequest.GetResponse();
Stream resStream = response.GetResponseStream();
StreamReader sr = new StreamReader(resStream, System.Text.Encoding.Default);
Response.Write ( sr.ReadToEnd());
resStream.Close();
sr.Close();
其中
WinHttpReq.SetRequestHeader "REMOTE_HOST", Request.ServerVariables("SERVER_NAME")
WinHttpReq.SetRequestHeader "URL", Request.ServerVariables("URL")
这个要如何在asp.net 中表现出来呢? |
|