Upload files with HTTPWebrequest (multipart/form-data)

后端 未结 21 2609
独厮守ぢ
独厮守ぢ 2020-11-21 04:53

Is there any class, library or some piece of code which will help me to upload files with HTTPWebrequest?

Edit 2:

I do not

21条回答
  •  眼角桃花
    2020-11-21 05:31

    something like this is close: (untested code)

    byte[] data; // data goes here.
    
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
    request.Credentials = userNetworkCredentials;
    request.Method = "PUT";
    request.ContentType = "application/octet-stream";
    request.ContentLength = data.Length;
    Stream stream = request.GetRequestStream();
    stream.Write(data,0,data.Length);
    stream.Close();
    response = (HttpWebResponse)request.GetResponse();
    StreamReader reader = new StreamReader(response.GetResponseStream());
    temp = reader.ReadToEnd();
    reader.Close();
    

提交回复
热议问题