Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7648901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:49:54+00:00 2026-05-31T10:49:54+00:00

I have to pass parameters to a WebRequest. The parameters are available as a

  • 0

I have to pass parameters to a WebRequest. The parameters are available as a NameValueCollection. I have to return a byte array.

How do I do that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T10:49:56+00:00Added an answer on May 31, 2026 at 10:49 am

    I’m assuming you mean HttpWebRequest, since WebRequest is just an abstract class. And, I’m assuming you’re doing a POST, since with a GET you can just slap it onto the end of the URL.

    So, you need to first create the body of the POST, which is written into the web requests’s request stream:

    var sb = new StringBuilder();
    foreach(var item in myCollection) {
      sb.AppendFormat("{0}={1}&", item.Name, HttpUtility.UrlEncode(item.Value.ToString()));
    }
    sb.Remove(sb.Length - 1, 1); // remove the last '&'
    

    At this point, you’ll have a string buffer that contains a string like "myVal1=Hello%20World&myVal2=5". Now you want to write it to the request’s stream:

    var request = (HttpWebRequest)HttpWebRequest.Create("http://somewhere.url/asdf/asdf");
    request.Method = "POST";
    var stream = request.GetRequestStream();
    var bytes = Encoding.UTF8.GetBytes(sb.ToString());
    request.ContentType="application/x-www-form-urlencoded;charset=UTF-8";
    request.ContentLength = data.Length;
    stream.Write(bytes, 0, bytes.Length);
    stream.Close();
    var response = (HttpWebResponse)request.GetResponse();
    // ... process the response ...
    

    Hope this helps. I assumed your NameValueCollection was in the form of string -> object. Adjust the “item.Value” part if it differs. I also didn’t URL Encode the key of a pair, since i don’t think they accept url-encoded keys.


    • Sending Data with WebRequest – MSDN
    • POST with C#
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have around 8-9 parameters to pass in a function which returns an array.
Background I have a web application that uses ISO-8859-1 encoding. When I pass parameters
I have a rake task that I want to pass parameters to. For example,
I have the following form that uses a GET to pass parameters to a
I have a SSRS report that I pass parameters to. Within the base report
I have two classes one of them that I pass to sends two parameters
I have to pass parameters between two rails apps. In one side (sender) I
I have spent multiple hours trying to figure out how to pass multiple parameters
Hallo, how can I pass more parameters to usort? I have different functions, which
I have a NameValueCollection with parameter. I want to pass all parameter in SqlCommand

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.