如何在Asp.Net MVC中的WebApi中使用Curl发布文件 [英] How to post file using Curl in WebApi in Asp.Net MVC

查看:56
本文介绍了如何在Asp.Net MVC中的WebApi中使用Curl发布文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要求,例如使用WebApi将xml文件发布到控制器中

I have an requirement like posting an xml file into the controller using WebApi

curl --form"file=@update.xml"

curl --form "file=@update.xml"

curl --form"file = update.xml"" http://localhost:60794/WebApi/Forms/Update?login = logger "

curl --form "file=update.xml" "http://localhost:60794/WebApi/Forms/Update?login=logger"

[AllowAnonymous]
public virtual ActionResult Update(string login)
{
    new HomeController().SetLoggedIn("logger");
    HttpPostedFileBase file = Request.Files["file"];
    StreamReader fileStream = new StreamReader(file.InputStream);

如果开发人员尝试使用给定的路径,则它的工作方式如下所示

If am trying to use the given path by the dev its is not working like below

curl --form"file = @ D:/update.xml"" http://localhost:60794/WebApi/Forms/Update?login = logger "

如何发布本地xml文件并执行此操作?

How to post the local xml file and do this operation?

推荐答案

语法和我使用的方法是错误的,我们不能在浏览器的URL中直接使用Curl来卷曲,我们需要Linux软件包和linux环境,否则我们可以使用cygwin软件通过Windows来实现.使用cygwin,我们需要使用该curl软件包安装curl软件包,我们必须转到该目录所在的文件夹,并且需要运行以下命令来开始执行操作.

Syntax and the method which i Used is wrong one, We cant use Curl directly in the URL in browser for curl we need linux packages and linux environment or else we can achieve it by windows using cygwin software. Using cygwin we needs to install the curl package using that curl package we have to goto the folder where that directory exists and we needs to run the below command to start doing the operation.

   curl --form "file=update.xml" "http://localhost:60794/WebApi/Forms/Update?login=logger"

这篇关于如何在Asp.Net MVC中的WebApi中使用Curl发布文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆