Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Antonio Ascione 1 post 71 karma points
    Sep 22, 2016 @ 12:44
    Antonio Ascione
    0

    UmbracoApiController method gets always Null data from POST

    Hi guys, I am new on this forum and I am struggling a lot with something that theoretically should be easy.

    I am calling a WebMethod in Umbraco that looks like this:

    public class WebMethodsController : UmbracoApiController {

        [System.Web.Http.AcceptVerbs("GET", "POST")]
        [System.Web.Http.HttpPost]
    
        public String CreateUpdateEvent([System.Web.Http.FromBody] NameValueCollection data)
    
        {
          ....some code here...
    
        }
    

    }

    From a separate web application (non Umbraco) in this way:

    var values = new NameValueCollection(); values["property1"] = "hello"; values["property2"] = "world";

        using (var client = new WebClient())
        {
    
            var response = client.UploadValues("http://raes.local/Umbraco/Api/WebMethods/CreateUpdateEvent", "POST", values);
    
            String responseString = Encoding.Default.GetString(response);
    

    }

    The issue is that the POST is triggering but the data from the [FromBody] of the post is always null. In other words I am not able to get the object sent via the POST.

    Am I missing something?

    Thank you in advance!!!

Please Sign in or register to post replies

Write your reply to:

Draft