Silverlight:RestSharp的HTTP DELETE和PUT方法 [英] Silverlight: HTTP DELETE and PUT methods with RestSharp

查看:154
本文介绍了Silverlight:RestSharp的HTTP DELETE和PUT方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从Silverlight访问内部REST API,但事实证明,我不允许使用POST或DELETE作为请求的HTTP方法.

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.

这样做总是导致SecurityException.

在Silverlight中使用REST api的推荐方法是什么?

What is the recommended way to use REST apis with Silverlight?

推荐答案

SecurityException可能意味着API没有适当的clientaccesspolicy.xml文件.这是一个非常宽容的示例,它允许所有HTTP方法和标头.我们已经成功地将其用于我们的API(这很流行,尽管我不知道从Silverlight获得多少流量).

SecurityException probably means the API doesn't have the proper clientaccesspolicy.xml file in place. Here's an example of a very lenient one that allows all HTTP methods and headers. We have used this successfully for our API (which is popular, though I don't know how much traffic we get from Silverlight).

<?xml version="1.0" encoding="utf-8" ?>
<access-policy>
  <cross-domain-access>
    <policy>
      <allow-from http-request-headers="*" http-methods="*">
        <domain uri="http://*" />
        <domain uri="https://*" />
      </allow-from>
      <grant-to>
        <resource path="/" include-subpaths="true" />
      </grant-to>
    </policy>
  </cross-domain-access>
</access-policy>

这需要放置在您要使用的API所在域的根目录下的clientaccesspolicy.xml文件中.

This needs to be placed in a clientaccesspolicy.xml file at the root of the domain the API you are trying to use is on.

这篇关于Silverlight:RestSharp的HTTP DELETE和PUT方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆