无效的URL GoError:K6性能测试中的URL值无效

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (8)

我通过K6 http.url运行API并获得以下异常。不确定网址中遗漏了什么?

export default function() {
  let url = http.get("http://test.loadimpact.com");
  let res = http.get(url);
  check(res, {
    "status was 200": (r) => r.status == 200,
        "transaction time OK": (r) => r.timings.duration < 200
    });
    sleep(1);   
}


WARN[0063] Request Failed                                error="Get http://test.loadimpact.com: dial tcp "ip":80: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond."
ERRO[0063] GoError: invalid URL value '&http.Response{ctx:(*context.valueCtx)(0xc003dfbb00), RemoteIP:"", RemotePort:0, URL:"http://test.loadimpact.com", Status:0, Proto:"", Headers:map[string]string(nil), Cookies:map[string][]*httpext.HTTPCookie(nil), Body:interface {}(nil), Timings:httpext.ResponseTimings{Duration:0, Blocked:0, LookingUp:0, Connecting:0, TLSHandshaking:0, Sending:0, Waiting:0, Receiving:0}, TLSVersion:"", TLSCipherSuite:"", OCSP:netext.OCSP{ProducedAt:0, ThisUpdate:0, NextUpdate:0, RevokedAt:0, RevocationReason:"", Status:""}, Error:"dial tcp "ip":80: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.", ErrorCode:1210, Request:httpext.Request{Method:"GET", URL:"http://test.loadimpact.com", Headers:map[string][]string{"User-Agent":[]string{"k6/0.24.0 (https://k6.io/)"}}, Body:"", Cookies:map[string][]*httpext.HTTPRequestCookie{}}, cachedJSON:interface {}(nil), validatedJSON:false}'
提问于
用户回答回答于

您将URL设置为http.get函数调用的结果,我认为您打算这样做:

export default function() {
  let url = "http://test.loadimpact.com";
  let res = http.get(url);
  check(res, {
    "status was 200": (r) => r.status == 200,
        "transaction time OK": (r) => r.timings.duration < 200
    });
    sleep(1);   
}

扫码关注云+社区

领取腾讯云代金券