I use HttpWebRequest to upload file on the server. But I also want to send some parameters (I mean name-value pairs)
            Asked
            
        
        
            Active
            
        
            Viewed 341 times
        
    0
            
            
        - 
                    What if I just add all my name-value pairs to the url? Something like that: localhost:8080/fileuploader?a=b&c=d . Should it work with POST? – Anton Kasianchuk Oct 12 '13 at 19:45
- 
                    see if this helps: http://msdn.microsoft.com/en-us/library/debx8sh9%28VS.80%29.aspx – Amar Oct 12 '13 at 20:13
2 Answers
1
            You can add them to the query string. They'll be available on the server, regardless of whether the HTTP method is POST or GET.
        Mike Van Vertloo
        
- 192
- 9
- 
                    OK. but in other hand, when I send a file to the server there is a file body in the post with delimiters. So can I add my parameters string to the request body? I mean before or after file body. I am not sure how POST body should looks like in this case. – Anton Kasianchuk Oct 12 '13 at 20:06
- 
                    Looks like you want the answer from this then: http://stackoverflow.com/questions/566462/upload-files-with-httpwebrequest-multipart-form-data This uploads the name/value collection as a separate part of the multipart POST request. – Mike Van Vertloo Oct 12 '13 at 20:13
0
            
            
        you can try this:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("some site");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
byte[] data = "some data";
request.ContentLength = data.Length;
using (Stream stream = request.GetRequestStream())
{
    stream.Write(data, 0, data.Length);
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        ST3
        
- 8,826
- 3
- 68
- 92
- 
                    Yes, but what I want is to send both file and parameters string. What should I write in the stream first? Can you clarify how to handle the situation when "some data" is a couple of file and parameters string – Anton Kasianchuk Oct 12 '13 at 20:57