Server Sided Proxy on Blogger

别来无恙 提交于 2019-12-12 03:15:16

问题


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?

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

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>

回答1:


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.

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. 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.


来源:https://stackoverflow.com/questions/10117343/server-sided-proxy-on-blogger

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!