0

I have some simple code here is my Put handler .

My problem is value is blank or my second write line doesn't work in either method. How come I am not accessing the post or puts body right?

  // PUT api/activate/5
    public void Put(int id, [FromBody]string value)
    {
        System.Diagnostics.Debug.WriteLine("Put !");
        System.Diagnostics.Debug.WriteLine(value);


    }

heres my Post Handler code

 public void Post([FromBody]String value)
        {
            System.Diagnostics.Debug.WriteLine("Post !");
            System.Diagnostics.Debug.WriteLine(value);


        }

heres the error i get

iisexpress.exe Information: 0 : Message='Action returned 'null'', Operation=ReflectedHttpActionDescriptor.ExecuteAsync iisexpress.exe Information: 0 : Operation=ApiControllerActionInvoker.InvokeActionAsync, Status=204 (NoContent) iisexpress.exe Information: 0 : Operation=ActivateController.ExecuteAsync, Status=204 (NoContent) iisexpress.exe Information: 0 : Response, Status=204 (NoContent), Method=PUT, Url=http://localhost:53676/api/activate/3, Message='Content-type='none', content-length=unknown' iisexpress.exe Information: 0 : Operation=ActivateController.Dispose The program '[14136] iisexpress.exe' has exited with code 0 (0x0).

this is how I am sending the put or post using postman

enter image description here

I get a 204 when sending it but that seems ok because I am not returning anything.

**What I am trying to do is access value from my asp.net code. Ie the writeline for value wont print anything because I cant get the value from the body correctly.

In a rails I would say response.body to access this server side. How do I access the data I posted in my asp.net code??**

Frank Visaggio
  • 3,642
  • 9
  • 34
  • 71
  • I do not see you returning any content from your Put and Post - – G-Man Mar 30 '15 at 13:40
  • its void do i have to? my issue is not being able to get the data I posted or puted in my asp.net server side code – Frank Visaggio Mar 30 '15 at 13:41
  • the 204 response that you are receiving is correct since your actions return void http://typecastexception.com/post/2014/09/28/ASPNET-Web-Api-Unwrapping-HTTP-Error-Results-and-Model-State-Dictionaries-Client-Side.aspx – G-Man Mar 30 '15 at 13:46
  • I think I worded the question wrong. My issue is how do I access the value of the body in my asp.net code. I can't seem to print that – Frank Visaggio Mar 30 '15 at 13:51

1 Answers1

1

Post Request in an MVC app are routed using names.
If you have http://localhost:53676/api/activate/?country=jordan
The method public void Post(string country) would recieve that Post Value.

Also use string Not String in methods, it is best practice even if they are the same in the end. See SO Answer

Community
  • 1
  • 1
juanvan
  • 671
  • 7
  • 19