如何重置/删除/清除请求正文

我必须将表单参数作为正文传递给我的请求。当我尝试

 Response post = request.urlEncodingEnabled(true).log().all().config(RestAssured.config()
            .encoderConfig(EncoderConfig.encoderConfig()
                    .encodeContentTypeAs("x-www-form-urlencoded",ContentType.URLENC)))

我收到的错误消息是“您可以在POST中发送表单参数或正文内容,而不能同时发送!”

当我检查日志时,以前的api响应作为正文传递给此请求。如何删除/重置/清除身体并仅通过表单参数。

salalaf 回答:如何重置/删除/清除请求正文

对于每个请求,您应始终使用新的 RequestSpecification 实例。

在每个新请求调用之前,应调用以下函数:

# Note: I start the positions at 0,# but you could change the method to allow for starting at 1
test_dataset = [
    {'value': 'A','start_position': 0,'end_position': 1},{'value': 'S','start_position': 2,'end_position': 3},{'value': 'A','start_position': 4,'end_position': 5},]

set_flag(test_dataset)  # returns: ['A','A','S','A']

RestUtil.java类

public void beforeNewRequest(){
        restUtils.resetRestAssured();            //reset existing instance
        restUtils = RestUtils.getInstance();     //get new instance
    }
本文链接:https://www.f2er.com/3139677.html

大家都在问