0

I have a simple Restful C# webservice contaning, with this post function:

public void Post(HttpRequestMessage value) 
    {
        if (value == null) Debug.WriteLine("Post *** Request. We got null");
        Debug.WriteLine("Post Request. We got: " + value);
       
    }

I'm testing it using a simple HTML page containing this code

<form action="http://localhost:44378/api/values" method="post">
      <input type="text" name="data" value="mydata" />
      <input type="submit" />
</form>

The Web service recieves the Post request, however it doesn't seem to get the data I send it. I get always null.

Any clues what's going wrong and what I should change?

Thanks alot.

  • May I suggest you check the .NET docs as there is quite a lot I don't think you understand: https://dotnet.microsoft.com/apps/aspnet/apis and https://stackoverflow.com/questions/17971548/how-to-get-httprequestmessage-data - also checkout Postman for an easy way to send requests to an API – Neil Thompson Aug 28 '20 at 14:23
  • I suggest you to give the parameter same name during POST...try HTTPRequestMessage data in the function parameter – Pratik.S Aug 28 '20 at 16:43

0 Answers0