Silverlight: HTTP DELETE and PUT methods with RestSharp

前端 未结 2 1994
不知归路
不知归路 2021-01-22 07:09

I wanted to access an internal REST API from Silverlight, but it turns out that I am not allowed to use POST or DELETE as the HTTP method for my request.

Doing so always

2条回答
  •  盖世英雄少女心
    2021-01-22 07:40

    Another solution I came up with is setting in RestSharp the X-HTTP-Method-Override header, and just send POST request.

    This might also be useful if you can just modify the client code, but the server has an unusuable clientaccesspolicy.xml.

    In my API class I use this code

    if (request.Method == Method.PUT || request.Method == Method.DELETE)
    {
        request.AddHeader("X-HTTP-Method-Override", request.Method.ToString());
        request.Method = Method.POST;
    }
    

提交回复
热议问题