CORS HttpChannel,如何给出正确的标题?

时间:2016-08-18 08:54:19

标签: c# .net ajax vb.net http

Google Chrome有一个扩展程序可将XML-RPC数据发送到服务器。服务器XML-RPC是桌面.NET应用程序。

这是初始化服务器的代码:

Dim properties As IDictionary = New Hashtable

properties.Item("name") = "hostChannel"
properties.Item("port") = 5678

Dim chnl As New HttpChannel(properties, Nothing, New XmlRpcServerFormatterSinkProvider)

Try

    ChannelServices.RegisterChannel(chnl, False)

    RemotingConfiguration.RegisterWellKnownServiceType(GetType(StateNameServer), "statename.rem", WellKnownObjectMode.Singleton)
    RemotingConfiguration.RegisterWellKnownServiceType(GetType(CoderServer), "statename.rem", WellKnownObjectMode.Singleton)

Catch ex As Exception

    MessageBox.Show("Ошибка")

End Try

向该服务器发送ajax请求时,保护会使CORS无法正常工作并导致加载项出错。

为此,服务器必须提供正确的标头。在OPTIONS上,来自浏览器的请求回复了代码200 OK

对于基于Apache的Web服务器,此问题已在域根目录中解析.htaccess个文件,其中包含以下内容。

Header set Access-Control-Allow-Origin "*"
Header always set Access-Control-Max-Age "1000"
Header always set Access-Control-Allow-Headers "X-Requested-With, Content-Type, Origin, Authorization, Accept, Client-Security-Token, Accept-Encoding"
Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT"

RewriteEngine On
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ blank.php [QSA,L]

如何解决前面提到的HttpChannel

的问题

0 个答案:

没有答案