using System;
using System.IO;
using System.Net;
using System.Text;
namespace xxxx
{
public class WebRequestPostExample
{
public static void Main()
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"http###files/Cygwin.pdf");
FileStream fs = new FileStream(@"D:\Cygwin.ISO", FileMode.Open, FileAccess.Read);
Byte[] bytes = new Byte[10240];
request.Method = "POST";
request.Proxy = null;
request.Headers.Add("XXX", "XXX");
request.ContentType = "application/octet-stream";
Stream dataStream = request.GetRequestStream();
int count = fs.Read(bytes, 0, 10240);
while (count != 0)
{
dataStream.Write(bytes, 0, count);
count = fs.Read(bytes, 0, 10240
REST接口POST方法发送文件到服务器(C#)
最新推荐文章于 2024-09-05 10:14:29 发布
本文介绍如何利用C#实现REST接口的POST请求,以上传文件到服务器。主要内容涉及字节流和类的使用。
摘要由CSDN通过智能技术生成