0

我正在为一家使用 Referer 的公司开发 WinJS 应用程序是他们的 API。

不幸的是,我找不到这样做的方法,即使是 Cookies!


这是一个代码示例:

Q.when(WinJS.xhr({
  url: "http://localhost:8888/api/auth/",
  type: "GET",
  headers: {
    "If-Modified-Since": "Mon, 27 Mar 1972 00:00:00 GMT",
    "Referer": "http://localhost:8888/api/"
  }
}));

WinRT 似乎使用 IE 和其他浏览器的相同行为。从请求中删除 Referer 和 Cookie 标头的位置。

任何解决方法?

4

2 回答 2

0

If you are using the Referer for authentication you should consider switching to a proper authentication system. Something like API keys.

Referer was never designed to be a tool for authentication, so it does a really bad job at it.

于 2013-01-18T14:02:57.247 回答
0

使用 AtomPubClient 作为解决方法怎么样?

尝试这个:

function doRequest3() {
    var reader;
    var client = Windows.Web.AtomPub.AtomPubClient();
    var uri = new Windows.Foundation.Uri("http://example.com");
    client.setRequestHeader("Referer", "http://localhost:8888/api/");
    client.retrieveMediaResourceAsync(uri).then(function(stream)
    {
        reader = Windows.Storage.Streams.DataReader(stream);
        return reader.loadAsync(999999);
    }).done(function (bytesRead) {
        var contentString = reader.readString(bytesRead);
        document.getElementById("content").innerText += "Content: " + contentString;
    }, function (error) {
        console.log(error);
    });
}
于 2013-01-20T00:49:20.707 回答