蝗虫io http POST在其他所有请求上均缺少标头

问题描述

我有一个locustfile.py,它反复发出相同的http发布请求。

第一篇文章包含了我期望的所有请求标头,并且该文章以http 200返回。

下一篇文章缺少所有标题,但Content-Length:0除外。这当然会失败。

它会继续进行其他所有具有适当内容长度,内容类型,授权等的请求。

关于为什么这些请求并不总是带有标题的任何建议?另外,我还注意到Postman中的类似行为。

更新:以下是我的locustfile.py。这似乎与Nginx服务器上的keep-alive有关。如何禁用locustfile中的keep-alive以便进一步测试?

from locust import TaskSet,task
from locust import HttpLocust
import os
from datetime import datetime


class UserBehavior(TaskSet):
    
    def __init__(self,*args,**kwargs):
        super(UserBehavior,self).__init__(*args,**kwargs)

    def on_start(self):
        # Use PID as unique name for locust instance
        self.__name = 'locust_'+str(os.getpid())
        self.__id = 1


    @task(1)
    def create_post(self):     
        date_time = datetime.Now().strftime("%Y-%m-%dT%H:%M:%s")
        data = "<xmldata timestamp= " + date_time + "> </xmldata>"

        user = 'username' 
        passwd = 'userpasswd' 
        header = {'Content-Type': 'application/xml','User-Agent': 'locust' }

        response = self.client.post('/path/'+str(self.__id)+'/info',data=data,headers=header,auth=(user,passwd),timeout=6000,name=self.__name)

        print("Response headers: " + str(response.headers))
        print("Request headers: " + str(response.request.headers))
        if response.status_code != 200:
           print("Response status code: " + str(response.status_code))
        if response.status_code > 200:
            print("Response content: " + response.text)
            print("Response reason " + response.reason)


class WebsiteUser(HttpLocust):
    task_set = UserBehavior      
    min_wait = 5000 
    max_wait = 10000  

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)