1
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 querystring parameter to a string object in C#/VB.NET

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

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

1

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(); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.