简体   繁体   English

使用C#中的http发布发送文件

[英]Send file using http post in c#

I am working with file posting in c#. 我正在使用C#进行文件发布。 I have posted a file from client side using ajax, with the following code 我已经使用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" />

and in the server side, i retrieved that file using the code, 在服务器端,我使用代码检索了该文件,

 HttpPostedFile hpf = Request.Files[0];

I need to send this file to another domain using http post. 我需要使用http发布将该文件发送到另一个域。 Is it possible to send that hpf using http post?. 是否可以使用http post发送该hpf?

I think you should be able to do that. 我认为您应该能够做到。 There are many ways to do that. 有很多方法可以做到这一点。 here is a link Upload files with HTTPWebrequest (multipart/form-data) 这是链接使用HTTPWebrequest上传文件(多部分/表单数据)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM