HttpWebRequest问题,请各位高手帮个忙,解决问题后马上结帐!!!在线等....
我想将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 中表现出来呢?
------解决方案--------------------顶
------解决方案--------------------学习ing ..
------解决方案--------------------myRequest.Headers.Add( "REMOTE_HOST ",
Request.ServerVariables( "SERVER_NAME ") ) ;
myRequest.Headers.Add( "URL ", Request.ServerVariables( "URL ") ) ;
___________
------解决方案--------------------System.Web.HttpRequest.ServerVariables[ " "]
------解决方案--------------------全都在这里了:
foreach(string key in Request.ServerVariables)
{
Response.Write(key + " = "+ Request.ServerVariables[key] + " <BR> ");
}
------解决方案--------------------顶~~~~~给分