|
I want to rewrite an XMLHTTP written by asp into HttpWebRequest with asp.net:
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
To:
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);
// Prepare the request...
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();
among them
WinHttpReq.SetRequestHeader "REMOTE_HOST", Request.ServerVariables("SERVER_NAME")
WinHttpReq.SetRequestHeader "URL", Request.ServerVariables("URL")
How can this be expressed in asp.net? |
|