可以在服务器上使用 JSONP 吗?

发布于 2024-09-03 05:52:22 字数 249 浏览 1 评论 0原文

我被困在具有中等信任设置的客户端主机上,该设置会阻止跨域请求并需要来自第三方域的数据。我现在可以选择使用 JSONP。

我使用来自客户端的 JSONP 和 jQuery 来绕过浏览器跨域安全性,并且我在 ASP.Net 3.5 中使用了 HttpWebRequest。

是否可以在服务器上使用 JSON,如果可以,如何使用?

我不认为是这样,但值得一问,因为我已经在服务器端编写了这个应用程序......

谢谢, 丹尼斯

I'm stuck on a clients host that has medium trust setup which blocks cross domain requests and need data from a 3rd party domain. I now have the option to use JSONP.

I've used JSONP from the client with jQuery to get around the browsers cross domain security and I've used HttpWebRequest in ASP.Net 3.5.

Is it possible to use JSON on the server and if so how?

I don't think it is, but worth asking seeing as I already have this app written server side....

Thanks,
Denis

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清风夜微凉 2024-09-10 05:52:22

最简单的方法可能只是通过服务器代理 JSONP 请求。如果这不是一个选项(因为数据必须在服务器上以某种方式处理),您可以手动从返回中删除函数调用,然后 JSON 解析其余部分

因此,如果 JSONP 调用返回:

F001( { "moose" : "sister" } )

首先,擦除直到第一个括号和最后一个括号之后的所有内容,因此您可以

{ "moose" : "sister" }

将其解析为您需要的任何内容。

The easy way might be just to proxy the JSONP request through your server. If that isn't an option (because the data must be processed in some way on the server) you can manually strip off the function-call from the return and then JSON-parse the rest

So if the JSONP call returns:

F001( { "moose" : "sister" } )

First, erase everything up to the first parenthesis and after the last so you have

{ "moose" : "sister" }

And parse that into whatever you need.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文