亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

如何用java放心上傳文件

如何用java放心上傳文件

慕萊塢森 2022-06-23 20:14:25
我們有一個 API,它從系統中獲取一個文件并在應用程序上顯示,為此我正在嘗試用放心和 Java 實現自動化我嘗試過,將圖像更改為二進制代碼,然后將其添加為不起作用的參數。Map<String, String> paramSample = new HashMap<>();    paramSample.put("api_key", "A813302*************");    paramSample.put("method", "my");    paramSample.put("body", "{\n" +            "  \"to\":\"91xxxxxxxx\",\n" +            " \"type\": \"image\", \"image\" : {\"caption\" : \"{{caption}}\"},\n" +            "\"callback\":\"{{callback}}\"\n" +            "}");    paramSample.put("from", "91xxxxxxx");    paramSample.put("file","C:\\Users\\sobhit.s\\Pictures\\SMS-2047.png");    RequestSpecification request = given();    Response responseSample = request.params(paramSample).get(ExecutionConfig.BASE_URL).then().extract().response();    String res=responseSample.prettyPrint();回應是——{    "status": "xxxx",    "message": "Invalid file format. Upload valid file."}
查看完整描述

1 回答

?
郎朗坤

TA貢獻1921條經驗 獲得超9個贊

首先,如果您不確定,請在 Postman 中執行此操作,然后在代碼中重新創建相同的內容。這樣,您將有一個郵遞員來演示您的編碼問題。


僅用于.queryParam()參數而不用于正文內容。正文內容應低于.body()


用于.multiPart()將文件作為多部分任務上傳。希望這可以幫助。


given().queryParam(

            "api_key", "A813302*************", 

            "method", "my",

            "from", "91xxxxxxx")

            .body("{\n" +

            "  \"to\":\"91xxxxxxxx\",\n" +

            " \"type\": \"image\", \"image\" : {\"caption\" : \"{{caption}}\"},\n" +

            "\"callback\":\"{{callback}}\"\n" +

            "}")

            .multiPart(new File("C:/Users/sobhit.s/Pictures/SMS-2047.png"))

            .when()

            .get(ExecutionConfig.BASE_URL)

            .prettyPrint();


查看完整回答
反對 回復 2022-06-23
  • 1 回答
  • 0 關注
  • 115 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號