普通POST方式上传 #### 普通Post方式上传 直接把文件用POST方式发给 uploadUrl 这个地址就行 ``` string uploadUrl = "http://47.92.121.230:9100/document/fileupload/qycode"; string result = ""; string boundary = "----------" + DateTime.Now.Ticks.ToString("x"); HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(uploadUrl); webrequest.ContentType = "multipart/form-data; boundary=" + boundary; webrequest.Method = "POST"; StringBuilder sb = new StringBuilder(); sb.Append("--"); sb.Append(boundary); sb.Append("\r\n"); sb.Append("Content-Disposition: form-data; name=\"file"); sb.Append("\"; filename=\"" + fileName + "\""); sb.Append("\""); sb.Append("\r\n"); sb.Append("Content-Type: application/octet-stream"); sb.Append("\r\n"); sb.Append("\r\n"); string postHeader = sb.ToString(); byte[] postHeaderBytes = Encoding.UTF8.GetBytes(postHeader); byte[] boundaryBytes = Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n"); webrequest.ContentLength = uploadFile.InputStream.Length + postHeaderBytes.Length + boundaryBytes.Length; Stream requestStream = webrequest.GetRequestStream(); requestStream.Write(postHeaderBytes, 0, postHeaderBytes.Length); byte[] buffer = new Byte[(int)uploadFile.InputStream.Length]; //声明文件长度的二进制类型 uploadFile.InputStream.Read(buffer, 0, buffer.Length); //将文件转成二进制 requestStream.Write(buffer, 0, buffer.Length); //赋值二进制数据 requestStream.Write(boundaryBytes, 0, boundaryBytes.Length); webrequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)"; WebResponse responce = webrequest.GetResponse(); requestStream.Close(); using (Stream s = responce.GetResponseStream()) { using (StreamReader sr = new StreamReader(s)) { result = sr.ReadToEnd(); } } responce.Close();```