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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
I’m assuming you mean
HttpWebRequest, sinceWebRequestis just an abstract class. And, I’m assuming you’re doing aPOST, since with aGETyou 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: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: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.