第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

如何使用“放心”請求 POST API 發(fā)送令牌和正文值?

如何使用“放心”請求 POST API 發(fā)送令牌和正文值?

慕田峪9158850 2022-09-28 16:08:33
我正在嘗試使用“放心”和“Java”為 POST API 創(chuàng)建一個(gè)測試自動化。此 POST API 具有作為應(yīng)用程序/JSON 的正文,如下所示:{    "customer":{        "email": "teste@mailinator.com"    },    "password":"Teste@12"}要發(fā)出此請求,我使用以下代碼,但它返回狀態(tài)代碼“400”,但我在Postman上發(fā)送相同的信息,它返回“200”:@And("envio as informacoes da chamada: (.*), (.*), (.*), (.*) e (.*)")        public void enviarDados (String srtEmail, String srtSenha, String srtAmbiente, String srtAPI, String srtToken) {HashMap<String,String> postContent = new HashMap<String,String>();            postContent.put("email", srtEmail);            postContent.put("password", srtSenha);            //System.out.println("{\"customer\":" +postContent+ "}");            given().contentType(ContentType.JSON).header("Authorization", "Bearer"+srtToken).header("Content-Type", "application/json").            //with().body(postContent).            with().body("{\"customer\":" +postContent+ "}").            when().post(srtAmbiente+srtAPI).            then().statusCode(200); }“400”的回應(yīng)是:{"status": 400,"message": "Malformed request","additional_error": ""}
查看完整描述

1 回答

?
慕慕森

TA貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超17個(gè)贊

您發(fā)送的正文與 POST 一起發(fā)送了不正確的正文。


//This line will not serialize HashMap to JSON, but call toString()

.body("{\"customer\":" +postContent+ "}")

因此,您的有效負(fù)載將如下所示:


{“客戶”:{密碼=密碼,customer=example@example.com}}


這不是有效的 JSON。試試這個(gè):


Map<String, String> emailContent = new HashMap<>();

emailContent.put("email", "example@example.com");

Map<String, Object> postContent = new HashMap<>();

postContent.put("customer", emailContent);

postContent.put("password", "password");

given().contentType(ContentType.JSON)

    .header("Authorization", "Bearer "+srtToken)

    .with().body(postContent)

    .when().post(srtAmbiente+srtAPI)

    .then().statusCode(200); 


查看完整回答
反對 回復(fù) 2022-09-28
  • 1 回答
  • 0 關(guān)注
  • 102 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號