405 Error when trying to POST from Windows Form application (WebClient Class)










0















I am trying to get a POST request working. I am using Windows Form and WebClient class to consume a REST Web API that I created. The windows form will transmit a list of object to the Rest Web API.



My WinApp Code



public static void BacklogListAdd(List<qmtRequest> _data)

var wi = System.Security.Principal.WindowsIdentity.GetCurrent();

var wic = wi.Impersonate();

var data = JsonConvert.SerializeObject(_data);

var urlLocal = "http://localhost:56499/request/item/add";
var url = "http://169.10.77.243/spa_solutions/ph18-mdm003-fe/request/item/add";

using (var client = new WebClient UseDefaultCredentials = true )

client.Headers.Add(HttpRequestHeader.ContentType,
"application/json; charset=utf-8");

client.UploadData(
"http://169.10.77.243/spa_solutions/ph18-mdm003-fe/request/item/wee",
"POST",
Encoding.UTF8.GetBytes(data));





Web API Code



[Authorize]
[HttpPost]
[Route("Item/Wee")]
public IHttpActionResult BacklogAddItem(List<qmtRequest> _RequestList)

using (qmtdb)

qmtdb.qmtRequests.AddRange(_RequestList);
qmtdb.SaveChanges();

return Ok();




I have done some troubleshooting though, it is working if I try to use GET instead of POST. Another note, when I try using POST in localhost it works.



Fiddler
enter image description here



Web Config



 <add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="GET, POST" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
<add name="Access-Control-Allow-Credentials" value="true" />









share|improve this question
























  • what is use of wi and wic parameteres?

    – Abid Hussain
    Nov 15 '18 at 9:53















0















I am trying to get a POST request working. I am using Windows Form and WebClient class to consume a REST Web API that I created. The windows form will transmit a list of object to the Rest Web API.



My WinApp Code



public static void BacklogListAdd(List<qmtRequest> _data)

var wi = System.Security.Principal.WindowsIdentity.GetCurrent();

var wic = wi.Impersonate();

var data = JsonConvert.SerializeObject(_data);

var urlLocal = "http://localhost:56499/request/item/add";
var url = "http://169.10.77.243/spa_solutions/ph18-mdm003-fe/request/item/add";

using (var client = new WebClient UseDefaultCredentials = true )

client.Headers.Add(HttpRequestHeader.ContentType,
"application/json; charset=utf-8");

client.UploadData(
"http://169.10.77.243/spa_solutions/ph18-mdm003-fe/request/item/wee",
"POST",
Encoding.UTF8.GetBytes(data));





Web API Code



[Authorize]
[HttpPost]
[Route("Item/Wee")]
public IHttpActionResult BacklogAddItem(List<qmtRequest> _RequestList)

using (qmtdb)

qmtdb.qmtRequests.AddRange(_RequestList);
qmtdb.SaveChanges();

return Ok();




I have done some troubleshooting though, it is working if I try to use GET instead of POST. Another note, when I try using POST in localhost it works.



Fiddler
enter image description here



Web Config



 <add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="GET, POST" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
<add name="Access-Control-Allow-Credentials" value="true" />









share|improve this question
























  • what is use of wi and wic parameteres?

    – Abid Hussain
    Nov 15 '18 at 9:53













0












0








0








I am trying to get a POST request working. I am using Windows Form and WebClient class to consume a REST Web API that I created. The windows form will transmit a list of object to the Rest Web API.



My WinApp Code



public static void BacklogListAdd(List<qmtRequest> _data)

var wi = System.Security.Principal.WindowsIdentity.GetCurrent();

var wic = wi.Impersonate();

var data = JsonConvert.SerializeObject(_data);

var urlLocal = "http://localhost:56499/request/item/add";
var url = "http://169.10.77.243/spa_solutions/ph18-mdm003-fe/request/item/add";

using (var client = new WebClient UseDefaultCredentials = true )

client.Headers.Add(HttpRequestHeader.ContentType,
"application/json; charset=utf-8");

client.UploadData(
"http://169.10.77.243/spa_solutions/ph18-mdm003-fe/request/item/wee",
"POST",
Encoding.UTF8.GetBytes(data));





Web API Code



[Authorize]
[HttpPost]
[Route("Item/Wee")]
public IHttpActionResult BacklogAddItem(List<qmtRequest> _RequestList)

using (qmtdb)

qmtdb.qmtRequests.AddRange(_RequestList);
qmtdb.SaveChanges();

return Ok();




I have done some troubleshooting though, it is working if I try to use GET instead of POST. Another note, when I try using POST in localhost it works.



Fiddler
enter image description here



Web Config



 <add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="GET, POST" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
<add name="Access-Control-Allow-Credentials" value="true" />









share|improve this question
















I am trying to get a POST request working. I am using Windows Form and WebClient class to consume a REST Web API that I created. The windows form will transmit a list of object to the Rest Web API.



My WinApp Code



public static void BacklogListAdd(List<qmtRequest> _data)

var wi = System.Security.Principal.WindowsIdentity.GetCurrent();

var wic = wi.Impersonate();

var data = JsonConvert.SerializeObject(_data);

var urlLocal = "http://localhost:56499/request/item/add";
var url = "http://169.10.77.243/spa_solutions/ph18-mdm003-fe/request/item/add";

using (var client = new WebClient UseDefaultCredentials = true )

client.Headers.Add(HttpRequestHeader.ContentType,
"application/json; charset=utf-8");

client.UploadData(
"http://169.10.77.243/spa_solutions/ph18-mdm003-fe/request/item/wee",
"POST",
Encoding.UTF8.GetBytes(data));





Web API Code



[Authorize]
[HttpPost]
[Route("Item/Wee")]
public IHttpActionResult BacklogAddItem(List<qmtRequest> _RequestList)

using (qmtdb)

qmtdb.qmtRequests.AddRange(_RequestList);
qmtdb.SaveChanges();

return Ok();




I have done some troubleshooting though, it is working if I try to use GET instead of POST. Another note, when I try using POST in localhost it works.



Fiddler
enter image description here



Web Config



 <add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="GET, POST" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
<add name="Access-Control-Allow-Credentials" value="true" />






c# rest iis






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 8:11









Kjartan

13.3k115577




13.3k115577










asked Nov 15 '18 at 7:19









rpreciosorprecioso

133




133












  • what is use of wi and wic parameteres?

    – Abid Hussain
    Nov 15 '18 at 9:53

















  • what is use of wi and wic parameteres?

    – Abid Hussain
    Nov 15 '18 at 9:53
















what is use of wi and wic parameteres?

– Abid Hussain
Nov 15 '18 at 9:53





what is use of wi and wic parameteres?

– Abid Hussain
Nov 15 '18 at 9:53












1 Answer
1






active

oldest

votes


















0














405 status code as Method Not Allowed Error .
Check you REST API method type and same method type call .
Hopefully you will get the response from your REST API






share|improve this answer


















  • 1





    As I have posted in my codes above, I am using "POST" for both the caller and the REST API Method. Also to note, the REST API is working if I use Postman.

    – rprecioso
    Nov 15 '18 at 8:14











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53314234%2f405-error-when-trying-to-post-from-windows-form-application-webclient-class%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














405 status code as Method Not Allowed Error .
Check you REST API method type and same method type call .
Hopefully you will get the response from your REST API






share|improve this answer


















  • 1





    As I have posted in my codes above, I am using "POST" for both the caller and the REST API Method. Also to note, the REST API is working if I use Postman.

    – rprecioso
    Nov 15 '18 at 8:14















0














405 status code as Method Not Allowed Error .
Check you REST API method type and same method type call .
Hopefully you will get the response from your REST API






share|improve this answer


















  • 1





    As I have posted in my codes above, I am using "POST" for both the caller and the REST API Method. Also to note, the REST API is working if I use Postman.

    – rprecioso
    Nov 15 '18 at 8:14













0












0








0







405 status code as Method Not Allowed Error .
Check you REST API method type and same method type call .
Hopefully you will get the response from your REST API






share|improve this answer













405 status code as Method Not Allowed Error .
Check you REST API method type and same method type call .
Hopefully you will get the response from your REST API







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 15 '18 at 8:04









Suraj KumarSuraj Kumar

1




1







  • 1





    As I have posted in my codes above, I am using "POST" for both the caller and the REST API Method. Also to note, the REST API is working if I use Postman.

    – rprecioso
    Nov 15 '18 at 8:14












  • 1





    As I have posted in my codes above, I am using "POST" for both the caller and the REST API Method. Also to note, the REST API is working if I use Postman.

    – rprecioso
    Nov 15 '18 at 8:14







1




1





As I have posted in my codes above, I am using "POST" for both the caller and the REST API Method. Also to note, the REST API is working if I use Postman.

– rprecioso
Nov 15 '18 at 8:14





As I have posted in my codes above, I am using "POST" for both the caller and the REST API Method. Also to note, the REST API is working if I use Postman.

– rprecioso
Nov 15 '18 at 8:14



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53314234%2f405-error-when-trying-to-post-from-windows-form-application-webclient-class%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kleinkühnau

Makov (Slowakei)

Deutsches Schauspielhaus