0

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"

[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"

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

Samaritan_Learner
  • 547
  • 1
  • 4
  • 26
  • Is there a particular error message, or any output at all from curl ? – Symeon Breen Aug 26 '16 at 12:16
  • Do you need to prefix the filename with `@` to have it recognized as such by curl? `--form "file=@update.xml"` – Ant P Aug 26 '16 at 12:29
  • Yes, I think so, my doubt is curl --form "file=@D:/update.xml" "http://localhost:60794/WebApi/form/Update?login=logger" if am using this above it is taking local computer path D drive as a server so its throwing error like "This site can’t be reached d’s server DNS address could not be found." So i want to know how to give th windows machine file path from local machine to server. @Symeon – Samaritan_Learner Aug 26 '16 at 13:14

2 Answers2

1

I have found in the past that curl on windows needs the double quotes escaped so maybe something like

curl --form 'upload=@\"D:/update.xml\"' "http://localhost:60794/WebApi/Forms/Update?login=logger"
Symeon Breen
  • 1,531
  • 11
  • 25
0

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"
Samaritan_Learner
  • 547
  • 1
  • 4
  • 26