How to send file in unirest. I tried sending through my code. it does not work but when I send it from postman it works fine.
File myfi = new File("/Users/xxxxxxx/Downloads/test.png");
MultipartBody request = Unirest.post("https://api.mom.io/v1/dad/parents")
.header("Content-Type", "application/x-www-form-urlencoded")
.header("api-key", "xxxxxxxxxxxx")
.queryString("to", "9189xxxxxxxxx")
.queryString("type", "media")
.queryString("body", "my Platform")
.queryString("channel", "mom")
.queryString("from", "xxxxxxxxxxx")
.queryString("callback_url", "https://webhook.site")
.queryString("lang_code", "en")
.field("media", myfi, "multipart/form-data;");
HttpResponse<String> response = request.asString();
System.out.println(response.getStatus());
System.out.println(response.getBody());
File f = new File("/path/downloads/logo.png");
MultipartBody r = Unirest.post("https://api.mom.io/v1/dad/parents")
.header("api-key", "xxxxxxxxxxxx").field("to", "9189xxxxxxxxx")
.field("channel", "mom").field("type", "media").field("from", "xxxxxxxxxxx")
.field("callback_url", "https://webhook.site")
.field("media", f).field("body", "test message");
HttpResponse<String> res = r.asString();
System.out.println(res.getBody());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.