在c#中使用http post发送文件

本文关键字:post 文件 http | 更新日期: 2023-09-27 18:07:05

我正在使用c#发布文件。我已经发布了一个文件从客户端使用ajax,与以下代码

<script type="text/javascript">
  function send() {
    var fd = new FormData();
    fd.append("fileToUpload", document.getElementById('filecontrol').files[0]);
    var xhr = new XMLHttpRequest();
    xhr.open("POST", "getFile.aspx");
    xhr.send(fd);
      }
</script>
<input type="file" id="filecontrol" />
<input type="button" onclick="getFile()" value="Upload File" />

,在服务器端,我使用代码

检索该文件
 HttpPostedFile hpf = Request.Files[0];

我需要使用http post将此文件发送到另一个域。可以使用http post发送hpf吗?

在c#中使用http post发送文件

我想你应该能做到。有很多方法可以做到这一点。这里是一个链接上传文件与HTTPWebrequest (multipart/form-data)