Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, how to get json response using httpclient my code is like
C#
var client = new HttpClient();
        client.BaseAddress = new Uri(strURL);
        string jsonData=@"{""strUser"":""AS"",""strPassword"":""SA"",""iCompanyId"" : ""108"", ""sMachineName"" : """"}";
        var content = new StringContent(jsonData,Encoding.UTF8,"application/json");
        HttpResponseMessage response=Task.Run(async()=>awaitclient.GetAsync(strURL)).Result;
        var result = await response.Content.ReadAsStringAsync();

it is showing "StatusCode: 405, ReasonPhrase: 'Method Not Allowed'" exception.Otherwise is there any way to get the response.
Thank you.

What I have tried:

var client = new HttpClient();
        client.BaseAddress = new Uri(strURL);
        string jsonData=@"{""strUser"":""AS"",""strPassword"":""SA"",""iCompanyId"" : ""108"", ""sMachineName"" : """"}";
        var content = new StringContent(jsonData,Encoding.UTF8,"application/json");
        HttpResponseMessage response=Task.Run(async()=>awaitclient.GetAsync(strURL)).Result;
        var result = await response.Content.ReadAsStringAsync();
Posted
Updated 13-Mar-17 1:23am
Comments
Michael_Davies 13-Mar-17 6:03am    
Try it as "application/x-www-form-urlencoded"

1 solution

"405 - Method not allowed", means you sent an HTTP command that the server not configured to handle...
As you are using GetAsync(), the method is GET... Check your server's OPTIONS to see what allowed...
It of course can be a problem with the data you never pass on (content?) too...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900