Access to XMLHttpRequest at 'https://miao.baidu.com/abdr?_o=file%3A%2F%2F' from origin 'null' has been blocked by CORS policy: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.
时间: 2023-12-22 12:03:14 浏览: 111
这是一个 CORS(跨域资源共享)错误,它表示浏览器阻止了从一个源访问另一个源的资源。这通常是由于安全原因引起的。错误信息中提到了一个“Access-Control-Allow-Origin”头,它告诉浏览器哪些源可以访问资源。如果这个头的值是一个通配符“*”,那么在请求中设置了“credentials(凭证)”时,浏览器会阻止访问。为了解决这个问题,需要在服务器上配置响应头,让它指定允许访问的源,或者将“withCredentials”属性设置为false。
相关问题
我使用PySide6.QtWebEngineWidgets.QWebEngineView时, 有如下提示信息,可以如何消除。 js: Access to XMLHttpRequest at 'https://miao.baidu.com/abdr?_o=file%3A%2F%2F' from origin 'file://' has been blocked by CORS policy: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.
这是因为你的请求被 CORS(跨域资源共享)策略所阻止了。默认情况下,Web浏览器只允许从同一域名下加载的资源进行AJAX请求,如果你想要从其他域名加载资源,就需要在服务器端设置允许跨域访问。
对于你的情况,因为你的请求包含了身份认证信息,所以浏览器不允许使用通配符"*"作为响应头中的"Access-Control-Allow-Origin"。这个问题可以通过设置响应头中的"Access-Control-Allow-Origin"值为请求的来源来解决。
如果你无法控制远程服务器的响应头,那么你可以考虑将请求发送到本地服务器,然后通过本地服务器进行转发。在转发时,你可以在本地服务器上修改响应头,从而解决跨域访问的问题。
如果你使用的是PySide6.QtWebEngineWidgets.QWebEngineView,你可以在创建QWebEnginePage实例时,设置QWebEngineProfile的内容,从而实现对跨域访问的控制。例如,你可以使用如下代码:
```python
from PySide6.QtWebEngineWidgets import QWebEngineProfile, QWebEnginePage
profile = QWebEngineProfile.defaultProfile()
profile.setHttpUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3")
profile.setPersistentCookiesPolicy(QWebEngineProfile.NoPersistentCookies)
profile.setHttpCacheType(QWebEngineProfile.MemoryHttpCache)
profile.setSpellCheckEnabled(False)
page = QWebEnginePage(profile, parent=self)
```
在这个例子中,我们设置了一个新的QWebEngineProfile,禁用了持久化Cookie,设置了HTTP缓存类型为MemoryHttpCache,并禁用了拼写检查。这个新的profile对象可以被用于创建QWebEnginePage实例。
希望这些信息可以帮助到你。
vue 报错Access to XMLHttpRequest at 'https://download.wuc0jp1e.com/d/image/dl?id=file%3A%2F%2F%2FpxLQEEmOvEVGF7WRPHirFFD8qtIST2yLCucESEuQ.png&enc=1' from origin 'http://localhost:7001' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
这个错误提示是因为你在使用 XMLHttpRequest 发起请求时,请求的 URL 不合法。根据错误提示中的 URL 'https://download.wuc0jp1e.com/d/image/dl?id=file:///pxLQEEmOvEVGF7WRPHirFFD8qtIST2yLCucESEuQ.png',可以看到其中包含了 file:// 协议,这个协议表示你请求的资源是本地文件系统中的文件,而不是网络上的资源。因此,你需要检查一下你的代码,看看是否正确配置了请求的 URL。一般来说,如果你要请求网络上的资源,应该使用 http:// 或 https:// 协议。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)