简体   繁体   中英

Send file using http post in c#

I am working with file posting in c#. I have posted a file from client side using ajax, with the following code

<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. Is it possible to send that hpf using http post?.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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