Click here to Skip to main content
15,889,872 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Detailed Error Message

{StatusCode: 405, ReasonPhrase: 'Method Not Allowed', Version: 1.1, Content: System.Net.Http.StreamContent, Headers: {   Pragma: no-cache   Cache-Control: no-cache   Date: Mon, 16 Sep 2019 03:31:46 GMT   Server: Microsoft-IIS/10.0   X-AspNet-Version: 4.0.30319   X-Powered-By: ASP.NET   Content-Length: 73   Allow: GET   Content-Type: application/json; charset=utf-8   Expires: -1 }}


What I have tried:

My C# code

#POST METHOD
 public ActionResult Insert(Student obj)
        {
            var client = new HttpClient();
            string stringData = JsonConvert.
        SerializeObject(obj);
            var contentData = new StringContent
        (stringData, System.Text.Encoding.UTF8,
        "application/json");
            HttpResponseMessage response = client.PostAsync
        ("http://localhost/api/student/", contentData).Result;
            ViewBag.Message = response.Content.
        ReadAsStringAsync().Result;
            return View(obj);

        }
#PUT METHOD
        public ActionResult Update(Student sdnt)
        {
            var client = new HttpClient();
            string stringData = JsonConvert.SerializeObject(sdnt);
            var contentData = new StringContent(stringData,
        System.Text.Encoding.UTF8, "application/json");
            HttpResponseMessage response = client.PutAsync
        ("http://localhost/api/student/" + sdnt.STDNT_ID,
        contentData).Result;
            ViewBag.Message = response.Content.
        ReadAsStringAsync().Result;
            return View("Insert");
        }
Posted
Updated 15-Sep-19 22:05pm

 
Share this answer
 
Comments
saifulhaque 17-Sep-19 1:38am    
Dear Richard ,

I tried different method using this link but not success.Can you provide exact link.
I hosted API web application in IIS and trying to post and put into this web application from another web application using above mentioned code.
Richard MacCutchan 17-Sep-19 2:49am    
I do not have an exact link, that is why I gave you the ones that Google found.
Decorate the action with HttpPut (needs "using System.Web.Http" at the top of the file)

[HttpPut]
public ActionResult Update(Student sdnt)
{
.....
}
 
Share this answer
 
Comments
saifulhaque 17-Sep-19 1:39am    
Yes.It already on the top.
F-ES Sitecore 17-Sep-19 5:06am    
If you didn't think it was important to include such an important bit of your code people are going to wonder what else of relevance you aren't telling us.

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