Riddhi Valecha

Riddhi Valecha

  • 444
  • 3.3k
  • 412.6k

WebApi- The remote server returned an error: (405) Method Not Allowed.

Mar 16 2021 6:41 PM
Hello Team,
 
I need 1 help.
 
I have a web api for updating records.
 
I am trying to update records, but I am getting error.
 
I am sharing my code -
  1. public String LoadUpdateIDOFSerialNumber(string id)  
  2. {  
  3. string resulat = "";  
  4. string strUrl = "";  
  5. string postdata = "";  
  6. try  
  7. {  
  8. strUrl = http://10.10.10.10/rs/fortpolio/aid/12345;  
  9. strUrl = string.Format(strUrl);  
  10. if (strUrl != "")  
  11. {  
  12. HttpWebRequest requestobjPost = WebRequest.Create(strUrl) as HttpWebRequest;  
  13. requestobjPost.Method = "POST";  
  14. requestobjPost.ContentType = "application/xml";  
  15. requestobjPost.Credentials = new NetworkCredential("user""user@123");  
  16. postdata = "1";  
  17. using (var streamWriter = new StreamWriter(requestobjPost.GetRequestStream()))  
  18. {  
  19. streamWriter.Write(postdata);  
  20. streamWriter.Flush();  
  21. }  
  22. var httpresponse = (HttpWebResponse)requestobjPost.GetResponse();  
  23. using (StreamReader reader = new StreamReader(httpresponse.GetResponseStream()))  
  24. {  
  25. resulat = reader.ReadToEnd();  
  26. }  
  27. }  
  28. else if (strUrl == "")  
  29. {  
  30. resulat = "Bad Request";  
  31. }  
  32. }  
  33. catch (Exception err) { err.Message.ToString(); }  
  34. return resulat;  
  35. }  
Error - The remote server returned an error: (405) Method Not Allowed.
 
Please help in solving this issue.

Answers (4)