bugVanisher/go-httpwrapper

get类型请求可以正常压测,post类型请求,会提示 http: ContentLength=195 with Body length 0 然后中断退出

Closed this issue · 4 comments

系统:windows10
golang版本:go version go1.14.6 windows/amd64
jsonstr:

`{
"debug": true,
"name": "5.2-项目信息保存",
"headers": {},
"init_variables": {
"Authorization": "{{ getRandomAuthorization }}",
"_dc": "{{ timestamp }}",
"cookie": "{{ getRandomCookie }}",
"ng3_logid": "{{ ng3Logid }}"
},
"running_variables": {},
"teststeps": [
{
"name": "1/SUP/RichHelp/GetHelpList",
"method": "POST",
"headers": {
"Authorization": "{{ .Authorization }}",
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36",
"X-Requested-With": "XMLHttpRequest",
"cookie": "{{ .cookie }}"
},
"url": "http://192.168.6.122:8000/SUP/RichHelp/GetHelpList?BusCode=&ORMMode=true&UIContainerID=&_dc={{ ._dc }}&helpid=pms3.wbs_type",
"body": "{"limit": "10", "ng3_logid": "{{ .ng3_logid }}", "orgId": "486191028000002", "outqueryfilter": "{\"phid_projprop\":\"4\"}", "page": "0", "propertyCode": "all", "propertyID": "all", "start": "0", "usePY": "true"}",
"validate": "{{ and (eq .http_status_code 200) }}"
}
]
}

控制台输出:
image

调试的入口:
是 GetTaskList 函数稍微处理之后,然后做脚本调试用的:

func RunRequest(baseJson string) {
rs := RunScript{}
err := jsoniter.Unmarshal([]byte(baseJson), &rs)
if err != nil {
panic(err)
}
rs.init()
for _, req := range rs.TestSteps {
req.parseVars(rs)
action := genReqAction(req)
action()
}
}`

因为testerhome今天登不了,没办法在帖子下面回复,只能提个issue了。。

更新一下,不知道是业务接口本身的问题还是什么问题。服务器返回的是有效的response,响应statuscode也是200.但是response,err := client.do 的操作,这里err就是会抛出一个 : unexpected EOF。昨天换了一个 request包resty,上面的这个接口可以正常解析了并请求了,换了一个更复杂的post接口后,发现还是会出现此类问题。response本身是具有有效值的。但是因为err的判断,进入了
if err != nil {
if verbose {
log.Printf(" %v\n", err)

后面解决这个post接口 请求 data 比较复杂的情况之后,这个issue再做更新。

post body 的格式更换为:key=value&key1=value1 ,然后client用上述的resty 。解决了上述问题。但是之前的某些post接口又不行了,这个问题目前很奇怪。

这个是调试的时候,加的日志,把client换成了自带的 net/http,也是一样的问题,单纯的某些接口,就是出现err不为空的情况。
代码:
image
控制台信息:
image
后面如果要按照这个不正常的方式进行处理,就得在err里面添加:boomer.RecordSuccess 和 boomer.RecordFailure 了。。如果大佬知道这个会err的原因,请麻烦回复一下,谢谢哈。

我知道了,换回 net/http 之后,是 body, err := ioutil.ReadAll(response.Body) 这个解析body出现了异常。上面内容错了。

修改成 :body, _ := ioutil.ReadAll(response.Body) ,不去处理这个err ,然后把if else 里面的boomer相关处理拿出来了。问题解决。

感谢分享。你这个issue我好像没收到提醒,没有及时回复你不好意思。如果你遇到了问题并解决了欢迎Pr给我