0
public void PostImport([FromBody]string file)
{}

By debugging I have entered method and see that file is always null, used a number of different requests, one of these should work (have also tried both with capital a for Application/json)? :

C:\>curl -X POST -H "Content-Type: application/json" -d "{\"\":\"myStr\"}" http://localhost:61393/api/admin/import

and

C:\>curl -X POST -H "Content-Type: application/json" -d "{\"file\":\"myStr\"}" http://localhost:61393/api/admin/import

My routes are set up as below

config.Routes.MapHttpRoute(
  name: "DefaultApi",
  routeTemplate: "api/{controller}/{id}",
  defaults: new { id = RouteParameter.Optional }
);

routes.MapRoute(
  name: "Default",
  url: "{controller}/{action}/{id}",
  defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
3

3 Answers 3

1

Can you try this?

curl -i -H "Accept: application/json" -X POST -d "=myStr" http://localhost:61393/api/admin/import

Instead of Content type header use accept header, it should work.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks. I find this very weird, why doesn't m$ support valid json ?
0

You should send an header for xhr ("XMLHttpRequest"), only then you would be able to hit your web-api. Try adding below header and run it.

"X-Requested-With": "XMLHttpRequest"

2 Comments

I'm not sure this is answer to the question. @NimChimpsky says he can stop debugger inside PostImport so request definitely reaches application.
@Kirill, I agree with you. I thought in web-api there may be restriction to populate params only when it is a XHR request.
0

Make sure your curl syntax is correct. This is the syntax from the curl manual:

curl -d "name=Rafael%20Sagula&phone=3320780" \ 
            http://www.where.com/guest.cgi

Did you try another rest client to test your application (e.g. Fiddler)?

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.