WebClient POST to MVC - data sometimes not received

I have a console app which uses WebClient to POST some json data to a web API. The web API is defined as:

        [AcceptVerbs("POST")]
        public HttpResponseMessage LoadContent(string token, CmsContent cmsContent)
        {

Open in new window


I have 2 test examples (data is received from a website) and one works and one doesn't. When I say doesn't work, I mean cmsContent is Null.

The posted json data is structurally correct and all values appear to be OK.

The data is readied and posted like this:

                var umbracoApiClient = new WebClient();
                umbracoApiClient.Headers[HttpRequestHeader.ContentType] = "application/json; charset=utf-8";
                var serialised = JsonConvert.SerializeObject(cmsContent);

                var url = new Uri( ... URL goes here ...);
                umbracoApiClient.Proxy = XmlHttpRequest.CreateProxy();
                umbracoApiClient.UploadString(url, serialised);

Open in new window


Is this an acceptable approach and how can I debug the issue of Null being received?
ascendinternetAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

apeterCommented:
WebAPI accepts only POST request. Are you making POST request ?
0
Bob LearnedCommented:
That would be  umbracoApiClient.Method = "POST", but UploadString sets the method to POST.  If you want to debug an issue with a web service, then you need to attach a debugger to the IIS worker process (if you are using IIS).
0
ascendinternetAuthor Commented:
I am using Visual Studio 2013 and have attached to the IIS process in order to see what is happening in the web service ... but the data being passed in (cmsContent) is null ... how do I see what is happening between the post and the web service.

I have checked that the data being passed to UploadString is valid.
0
käµfm³d 👽Commented:
how do I see what is happening between the post and the web service
Use a tool like Fiddler.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
apeterCommented:
You don't need to pass the token ? Just the cmscontent ?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.