1
string Url = ConfigurationManager.AppSettings["DataUrl"];
DateTime trndate = DateTime.Now.Date;     
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(Url);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = client.GetAsync(Url +"?id="+ trndate.ToString("yyyy-MM-dd")).Result;


Above method worked Successfully but post method not worked.My Post method Calling Code is.

HttpClient Postclient = new HttpClient();
Postclient.BaseAddress = new Uri(Url);
Postclient.DefaultRequestHeaders.Accept.Clear();
 Postclient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
PostRemote rr = new PostRemote();
rr.id= 123;
rr.age= 38;
HttpResponseMessage postresponse = Postclient.PostAsJsonAsync(Url, rr).Result;


An exception occrued Error message is

"Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.**

1
  • Yes it works.thank you. Commented Oct 19, 2016 at 8:16

1 Answer 1

1

This issue has been faced many times, and just have a simple solution.

Go to Tools > NuGet Package Manager and Select Package Manager Console. Execute the following two commands:

uninstall-package newtonsoft.json -force

install-package newtonsoft.json

And add/change code in your web.config

 <dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30AD4FE6B2A6AEED" culture="neutral"/>
     <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="9.0.0.0"/>
 </dependentAssembly>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.