Uploading zip file with POST/httpwebrequest in C#

前端 未结 1 903
故里飘歌
故里飘歌 2021-01-22 13:45

I\'m trying code from http://www.paraesthesia.com/archive/2009/12/16/posting-multipartform-data-using-.net-webrequest.aspx to do a POST through httpwebrequest.

If I try

相关标签:
1条回答
  • 2021-01-22 14:25

    BinaryReader should work indeed:

    FileInfo fInfo = new FileInfo(file.FullName);
    // 
    long numBytes = fInfo.Length;
    
    FileStream fStream = new FileStream(file.FullName, FileMode.Open, FileAccess.Read);
    
    BinaryReader br = new BinaryReader(fStream);
    
    byte[] bdata = br.ReadBytes((int)numBytes);
    
    br.Close();
    
    fStream.Close();
    
    // Write bdata to the HttpStream
    HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("url-here");
    // Additional webRequest parameters settings.
    HttpStream stream = (Stream)webRequest.GetRequestStream();
    stream .Write(bdata, 0, bdata.Length);
    stream.Close();
    
    HttpWebResponse response = (HttpWebRewponse)webRequest.GetResponse();
    
    0 讨论(0)
提交回复
热议问题