簡體   English   中英

保證沒有設置Content-Type

[英]restassured is not setting Content-Type

我正在使用https://github.com/jayway/rest-assured (版本3.2.1)來測試REST API,但是在設置Content-Type時遇到問題。

我正在做下面的測試,

@Test
    public void testSendContentType(){
        String str = givenThat()
                .when()
                .contentType(ContentType.URLENC)
                .get(URL).asString();
        System.out.println(str);
    }

執行測試后,我設置了以下標頭。

捕獲的標頭

Expires: Mon, 30 Jun 2014 14:33:21 GMT
Vary: Accept-Encoding
Content-Encoding: gzip
Connection: close
Transfer-Encoding: chunked
Content-Type: application/json;charset=utf-8

我調試並查看了代碼,但無法理解內容類型是如何設置的,以及為什么它沒有設置我提供的內容類型。

我也嘗試跟隨但沒用

.header("Content-Type", ""application/x-www-form-urlencoded")

您應該可以使用以下方法設置內容類型:

given().contentType(ContentType.URLENC). .. 

但是,為GET請求使用x-www-form-urlencode感覺很奇怪,因為GET請求不應包含主體。 通常,REST Assured會指出,如果在請求中提供表單參數,則應該使用x-www-form-urlencoded。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM