【问题标题】:jenkins: HTTP Request Plugin is returning Status 200 instead of contentjenkins:HTTP 请求插件返回状态 200 而不是内容
【发布时间】:2020-12-11 17:40:28
【问题描述】:

我正在尝试使用 jenkins httpRequest 来获取网页的内容,但奇怪的是我只得到 状态 200 而不是实际代码。以下是可重现的脚本及其控制台日志。

pipeline {
    agent any
    environment {
        def response = httpRequest "https://news.yahoo.com/"
        }
        stages {
            stage('Build'){
                steps {
                    script {
                        echo "${response}"
                        echo response.getContent()
                    }
                }
            }
        }
    }

控制台日志:

HttpMethod: GET
URL: https://news.yahoo.com/
Sending request to url: https://news.yahoo.com/
Response Code: HTTP/1.1 200 OK
Success code from [100‥399]
....
Status: 200
....
hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: java.lang.String.getContent() is applicable for argument types: () values: []

【问题讨论】:

    标签: jenkins jenkins-pipeline jenkins-plugins


    【解决方案1】:

    根据官方文档hereresponse.content 包含没有标题的响应内容。

    所以你的代码应该是这样的:

    pipeline {
        agent any
        environment {
            def response = httpRequest "https://news.yahoo.com/"
            }
            stages {
                stage('Build'){
                    steps {
                        script {
                            echo "${response}"
                            echo response.content
                        }
                    }
                }
            }
        }
    

    【讨论】:

      猜你喜欢
      • 2020-07-30
      • 2019-03-23
      • 2016-06-22
      • 1970-01-01
      • 1970-01-01
      • 2018-05-28
      • 2018-12-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多