Rails 代理控制器未正确拉取图像,如何适当修改? [英] Rails proxy controller not pulling images through properly, how to modify appropriately?
问题描述
我必须在 Rails 3.1 应用程序上实现代理以解决一些跨域 JS 问题.
I'm having to implement a proxy on a Rails 3.1 app to overcome some cross-domain JS issues.
到目前为止,我检索网页文本源似乎是正确的,但是它通常会丢失页面中的图像(可能是相对路径?),然后当我使用绝对路径指向图像时,它将显示 图像的ascii编码而不是图像本身,我认为出于熟悉的人的代码的明显原因与主题.
So far I have it retrieving web page text source seemingly right, however it commonly misses images (perhaps relative paths?) in the page and then when I direct it with an absolute path to an image it will show the ascii encoding of the image rather than the image itself, I think for obvious reasons from the code for someone familiar with the topic.
我希望有人能够修改以下代码,以便在图像代理情况下也能正常工作:
I was hopeful that someone would be able to revise the following code so as to work also properly with an image proxy situation:
proxy_controller.rb:
class ProxyController < ApplicationController
def get
url = URI.parse(params["url"])
result = Net::HTTP.get_response(url)
render :text => result.body
end
end
routes.rb:
get "proxy" => "proxy#get", :as => "proxy"
通过以下方式调用:
http://<my_dev_server>/proxy?url=http://<somedomain.tld>/path/to/page/images/image.jpg
或
http://<my_dev_server>/proxy?url=http://<somedomain.tld>/path/to/page
推荐答案
这篇关于Rails 代理控制器未正确拉取图像,如何适当修改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!