开发者

Need Help in converting Classic ASP Code to ASP.NET code

Set xml = Server.CreateObject("Microsoft.XMLHTTP")
xml.Open "GET", "http://www.indexguy.com/request_server.cfm?member_id=15893&id="+request.querystring("id")+"&"+request.querystring, False
xml.Send

How can I build the qu开发者_如何学Goerystring parameter to a string object in C#/VB.NET

"member_id=15893&id="+request.querystring("id")+"&"+request.querystring"


If you are looking to build a querystring, String.Format("{0}", arg) might be a cleaner method to construct it.


For ASP.NET, you're going to want to replace the Server.CreateObject("Microsoft.XMLHTTP") with HttpWebRequest.

As for building the query string, that's still identical. You can still retrieve query string parameters by indexing into Request.QueryString. If you're using C# you can keep the + for string concatenation but might be more acceptable to use & in VB.


In ASP.NET the Page class exposes a Request property which provides access to a QueryString property - this is a NameValueCollection that lets you get values out in much the same way as in your existing example, by specifying keys:

var id = Page.Request.QueryString("id");

var newQuery = string.Format("?member_id=15893&id={0}&", id);

The above can easily be expanded to build more into your required query string.

As for the request you're initiating, that can be achieved using a WebRequest instance; to alter the sample from MSDN only slightly, here is an example:

WebRequest request = WebRequest.Create(yourUrl + newQuery);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();   
Response.Write(response.StatusDescription);

Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader (dataStream);
string responseFromServer = reader.ReadToEnd();
Response.Write(responseFromServer);

reader.Close();
dataStream.Close();
response.Close();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜