跨域请求不CORS或JSONP [英] Cross-Domain Request without CORS or JSONP

查看:283
本文介绍了跨域请求不CORS或JSONP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题已经问过,但没有一个答案已经为我工作!我做一个学校项目,我想获得的HTML(解析它为我的项目),我的学校服务器上的动态调度文件恢复。

I know this question has been asked before, but none of the answers have been working for me! I am doing a school project and I would like to get the HTML (to parse it for my project) returned by the dynamic schedule files on my schools server.

我想的HTML页面是: https://telaris.wlu.ca/ ssb_prod / bwckschd.p_disp_dyn_sched

The page I would like the HTML of is: https://telaris.wlu.ca/ssb_prod/bwckschd.p_disp_dyn_sched

我觉得没有启用CORS为学校服务器上的文件,我不知道它是否支持JSONP ...

I think that CORS is not enabled for the school server files and I do not know if it supports JSONP...

如何建立跨域请求,从这个页面获取HTML?

我曾尝试:

$.ajax({
    type:'POST',
    url: 'https://telaris.wlu.ca/ssb_prod/bwckschd.p_disp_dyn_sched',
    headers: {
      'Access-Control-Allow-Origin': '*'
   },
   contentType: 'text/html',
   crossDomain:true
}).done(function( data ) {

});

和我得到的错误:

XMLHtt prequest无法加载 https://telaris.wlu.ca/ ssb_prod / bwckschd.p_disp_dyn_sched 。没有访问控制 - 允许 - 原产地标头的请求的资源present。原产地'空',因此没有允许访问。响应有HTTP状态code 501。

XMLHttpRequest cannot load https://telaris.wlu.ca/ssb_prod/bwckschd.p_disp_dyn_sched. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 501.

当我补充一下:

dataType:'jsonp'

我得到的错误:

I get the error:

GET <一href="https://telaris.wlu.ca/ssb_prod/bwckschd.p_disp_dyn_sched?callback=jQuery21108736664191819727_1416964243449&_=1416964243450" rel="nofollow">https://telaris.wlu.ca/ssb_prod/bwckschd.p_disp_dyn_sched?callback=jQuery21108736664191819727_1416964243449&_=1416964243450 400(错误请求)jquery.min.js:4send jquery.min.js:4n.extend.ajax jquery.min.js:4(匿名函数)

GET https://telaris.wlu.ca/ssb_prod/bwckschd.p_disp_dyn_sched?callback=jQuery21108736664191819727_1416964243449&_=1416964243450 400 (Bad Request) jquery.min.js:4send jquery.min.js:4n.extend.ajax jquery.min.js:4(anonymous function)

任何帮助是极大AP preciated!

Any help is greatly appreciated!

推荐答案

浏览器实施的同源访问控制,除非该网站明确允许跨起源请求(通过CORS或JSONP)。所以,如果你正在试图访问的网站不允许跨起源请求,那么你就不能使用浏览器的网站获取数据直接。它只是不会允许它(合法安全原因)。

Browsers enforce "same-origin" access control unless the site explicitly allows cross origin requests (either via CORS or JSONP). So, if the site you are trying to access does not allow cross origin requests, then you cannot get the data directly from the site using a browser. It simply won't allow it (for legitimate security reasons).

这意味着你将需要使用某种形式的第三方代理,可以得到的数据给你。这样做的两种最常见的方式是:

This means that you will need to use some sort of third party agent that can get the data for you. The two most common ways of doing that are:

  1. 您自己的服务器。你让你自己的服务器的请求获得来自其他服务器的一些内容。您的服务器,然后获取来自其他服务器的数据并将其返回到您的浏览器。

  1. Your own server. You make a request of your own server to get some content from some other server. Your server then fetches the data from the other server and returns it to you in the browser.

一个代理服务器。但是也有一些内置只是做的是在选择#1中描述的一些preconfigured代理服务器。您可以使用代理服务或安装自己的代理服务器来为你做这个或配置自己的Web服务器有这个能力。

A proxy server. There are some preconfigured proxy servers that are built just for doing what is described in option #1. You can either use a proxy service or install your own proxy server to do this for you or configure your own web server to have this capability.

这篇关于跨域请求不CORS或JSONP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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