1

I need to use C# to send a file to with the content-type of application/octet stream.

I can create an HttpWebRequest like the below:

 HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://test.com"); request.Headers.Add("content-type", "application/octet-stream"); //Add file here? HttpWebResponse response = (HttpWebResponse)request.GetResponse(); if (response.StatusCode == HttpStatusCode.Created) { Console.WriteLine("YAYA"); } else { Console.WriteLine("OH NO MR BILL!!!!"); } 

How do I accomplish the addition of the file into my stream?

6
  • social.msdn.microsoft.com/Forums/en-US/… Commented Jan 30, 2015 at 21:04
  • 2
    new Webclient().UploadFile(url, fname); Commented Jan 30, 2015 at 21:07
  • @EZI I need to be able to read the response back. Can you do that with WebClient? Commented Jan 30, 2015 at 21:11
  • See what above code returns.... Commented Jan 30, 2015 at 21:27
  • 1
    possible duplicate of Upload files with HTTPWebrequest (multipart/form-data) Commented Jan 30, 2015 at 21:31

1 Answer 1

1

Just get the request stream and then copy from your source stream.

using (var requestStream = request.GetRequestStream()) { fileStream.CopyTo(requestStream); } 
Sign up to request clarification or add additional context in comments.

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.