<summary>
Uploading files
</summary>
<param name= "uristr" > Server URL </param>
<param name= "name" >http message header name</param>
<param name= "filename" > file name </param>
<param name= "Data" > Documentation </param>
<param name= "offset" > File data Start location </param>
<param name= "Count" > File data length </param>
<returns></returns>
Static Public stringUpload (stringURISTR,stringNamestringFileName,byte[] Data,intOffsetintcount) { Try { varRequest =WebRequest.Create (URISTR); Request. Method="POST"; varBoundary = $"******{datetime.now.ticks}***"; Request. ContentType= $"multipart/form-data; boundary={boundary}"; Boundary= $"--{boundary}"; using(varRequeststream =request. GetRequestStream ()) {varBuffer = Encoding.ASCII.GetBytes (boundary +Environment.NewLine); requestStream.Write (Buffer,0, buffer. Length); Buffer= Encoding.ASCII.GetBytes ($"content-disposition:form-data; name=\ "{name}\"; filename=\ "{filename}\" {Environment.NewLine}"); requestStream.Write (Buffer,0, buffer. Length); Buffer= Encoding.ASCII.GetBytes ($"Content-type:application/octet-stream{environment.newline}{environment.newline}"); requestStream.Write (Buffer,0, buffer. Length); requestStream.Write (data, offset, count); Buffer= Encoding.ASCII.GetBytes ($"{environment.newline}{boundary}--"); requestStream.Write (Buffer,0, buffer. Length); } using(varResponse =request. GetResponse ())using(varResponsestream =Response. GetResponseStream ())using(varStreamReader =NewStreamReader (Responsestream)) { returnStreamreader.readtoend (); } } Catch { return NULL; } }
C#http Post File data