Blogger上的服务器端代理 [英] Server Sided Proxy on Blogger

查看:97
本文介绍了Blogger上的服务器端代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的博客页面上,我具有一个向外部域发出XMLHttpRequest的功能.显然,由于跨域限制,它不起作用.

On my blogger page i have a function that makes a XMLHttpRequest to an external domain. Apparently, it doesn't work because of the cross-domain restrictions.

是否可以为博客作者设置服务器端代理?

Is it possible to set up a server side proxy for blogger?

我在想或者还有什么可以代替 XMLHttpRequest

I'm thinking that or is there something else i can use instead of XMLHttpRequest

对不起,我真的是Web编程语言的新手,我们将不胜感激,谢谢!

I'm sorry, I'm really new to web programming language, any help would be appreciated, thanks!

<div id="poll">

Do you like this?

<input type="radio" name="poll" id="poll1" checked>Yes, it`s great

<input type="radio" name="poll" id="poll2">Yes...

<input type="radio" name="poll" id="poll3">Not bad...

<input type="radio" name="poll" id="poll4">No!

<input type="button" value="Vote!" onClick="vote();"/>
</div>


<script type="text/javascript">

function vote(){

for(var i=1;i<=4;i++){
if(document.getElementById('poll' + i).checked){

<script type="text/javascript"
     src="http://server2.example.com/vote.php?vote=i&jsonp=parseResponse">

function Call({"vote": i});

</script>
}
}
document.getElementById('poll').innerHTML = parseResponse;
}

</script>

推荐答案

您可以使用称为的东西. JSONP ,但前提是您所调用的网站提供的API将以正确的格式返回响应.

You can use what has become known as JSONP, but only if the site you're calling provides an API that will return a response in the correct format.

否则,是的,通常可以在任何Web容器的顶部实现服务器端代理支持.这就要求您具有直接访问服务器的权限(即,如果您的网站托管在blogger.com上,则该服务器将无法工作),具体细节将取决于您的实现语言和网络容器.但是,高级流程非常简单:

Otherwise, yes, it is generally possible to implement server-side proxy support on top of any web container. This requires that you have direct access to the server (i.e. it won't work if your site is hosted on blogger.com), and the exact specifics will vary depending upon your implementation language and web container. The high-level flow is very simple, however:

  1. 客户端使用标准XMLHttpRequest通过诸如/proxyRequest?url=http://www.crossdomain.com/someNeatThing之类的请求回调服务器.
  2. 服务器触发对"http://www.crossdomain.com/someNeatThing"的请求,获取响应,并通过proxyRequest调用将其通过管道传回客户端.
  1. The client calls back to the server with a request like /proxyRequest?url=http://www.crossdomain.com/someNeatThing, using a standard XMLHttpRequest.
  2. The server fires off its own request to 'http://www.crossdomain.com/someNeatThing', grabs the response, and pipes it back to the client as the result of the proxyRequest call.

这篇关于Blogger上的服务器端代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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