我刚刚交了一个使用Jodd库的groovy项目(我对此没什么经验)。我希望了解如何设置配置,以便可以在公司代理后面进行http和https调用。
目前已设置帮助程序类
#! /usr/bin/groovy
package org.myOrg
import groovy.json.JsonBuilder
@Grab("org.jodd:jodd-http:3.8.5")
import jodd.http.HttpRequest
/**
* Helper class for making REST calls from a Jenkins Pipeline job.
*/
class JenkinsHttpClient {
// Constants
private static final String USER_AGENT = "User-Agent";
private final HttpRequest httpRequest
private final String userAgent = 'Jenkins'
JenkinsHttpClient() {
httpRequest = new HttpRequest()
}
/**
* GET method
* @param url - This is the endpoint
* @return response body as String
*/
private def get(String url) {
def resp = httpRequest.get(url)
.header(USER_AGENT, userAgent)
.send()
return resp.bodyText()
}
我如何或在何处添加配置以使其在代理服务器后面工作?
答案 0 :(得分:1)
currentNumber = ... get the next number ...
if( abs(currentNumber - previousNUmber) > maximumDifference )
{
// do whatever trigger action is required
}
// now update the saved last number
previousNumber = currentNumber;
还允许您指定代理。只需为HttpConnectionProvider
实例提供有关所用代理的信息(类型,地址,端口,用户名,密码):
ProxyInfo
Jodd支持HTTP,SOCKS4和SOCKE5代理类型。
请参阅documentation。