首页 > 解决方案 > 使用 Vue/Axios 调用访问 Jenkins api 的问题

问题描述

我尝试使用 axios 从我的 Vue js 代码库/环境到 Jenkins API 进行 get 调用,但我无法这样做。

我已经阅读了我可以但无法解决这个特定问题的所有资源。我什至创建了一个 .htaccess 文件来查看它是否有帮助但没有用。我用完了所有选项,所以我来这里寻求帮助。

下面是我在 App.vue 文件中使用的 axios 代码。

axios.get(
    *URL to access Jenkins that is currently running on a tomcat server*,
    {
        headers: {
            "jenkins-crumb": "* Some numbers and letters*",
        },
        auth: {
            username: "*obvious username*",
            password: "*obvious password*"
        },
        withCredentials: true,
        crossdomain: true
    }
)
.then(response => (this.info= response)).catch(error => (console.log(error)));

控制台日志输出:

从源“ http://localhost:8080 ”访问“url”处的 XMLHttpRequest已被 CORS 策略阻止:对预检请求的响应未通过访问控制检查:不存在“Access-Control-Allow-Origin”标头在请求的资源上。

网络输出:

一般
请求 URL:URL
请求方法:OPTIONS
状态代码:403
远程地址:localhost:8080
推荐人策略:no-referrer-when-downgrade

请求
标头 显示临时标头
Access-Control-Request-Headers: authentication,jenkins-crumb
Access-Control-Request-Method: GET
Origin: http://localhost:8080
Referer: http://localhost:8080/
User-Agent : Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, 像 Gecko) Chrome/77.0.3865.90 Safari/537.36

请帮忙!

标签: vue.jsjenkinsjenkins-api

解决方案


推荐阅读