Rajesh B Rajesh B - 1 year ago 181
ASP.NET (C#) Question

How to post file using Curl in WebApi in Asp.Net MVC

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

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

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

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"

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

Answer Source

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"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download