retrofit

Retrofit POST Request with body parameters android

佐手、 提交于 2020-07-10 07:51:35
问题 I need to execute post request with retrofit but i have a problem which i can't understand very well. Before trying with code i tested api call with Postman and request look like this: Here is my android code: public class API { private static <T> T builder(Class<T> endpoint) { return new Retrofit.Builder() .baseUrl(Utils.API_BASE_URL) .addConverterFactory(ScalarsConverterFactory.create()) .addConverterFactory(GsonConverterFactory.create()) .build() .create(endpoint); } public static

How to post array parameters with Retrofit?

夙愿已清 提交于 2020-07-08 11:20:38
问题 I want to post data as follows: { "user_id":"14545646", "list":["4545645","4545645","4545645","4545645"] } I used the following Retrofit method: interface DeleteOrder { @FormUrlEncoded @POST("/api/shop/deleteOrder.json") void getPoJoDeleteOrder(@Field("user_id") String user_id, @Field("list") String[] list,Callback<PoJoDeleteOrder> callback); } Is this the correct way? 回答1: if have many user,then use FieldMap . user[0][email]= &user[0][password]= &user[1][email]= &user[1][password]= @POST("

Spring Boot multipartfile always null

淺唱寂寞╮ 提交于 2020-07-04 08:51:46
问题 I am using Spring Boot version = '1.4.0.RC1' with Spring Boot Stormpath 1.0.2. I am trying to use multipart file upload but the MultipartFile is always null in the controller. When I use @RequestPart("file") the info: "status":400,"error":"Bad Request","exception":"org.springframework.web.multipart.support.MissingServletRequestPartException","message":"Required request part 'file' is not present" When I use @RequestPart(name = "file", required = false), the part is always null. However, if I

how to display field is missing error response from api using retrofit?

两盒软妹~` 提交于 2020-06-29 03:41:15
问题 I'm making an login page.What i have done is--> 1.When user typed right login details -->it will take him to next successful home page 2.When user typed wrong login details-->displayed an error response from API that email or password is wrong try again later.. So basically what I want is--> When user forgot to fill field like email or password, it should give response from API like "data is missing". Here is my json: { "status": 400, "message": "Data missing.", "user_msg": "Data missing" }

Bad Request [400], FCM Legacy HTTP API with Retrofit

放肆的年华 提交于 2020-06-17 09:42:09
问题 URL = https://fcm.googleapis.com/fcm/send Request Body { "registration_ids": ["token 1","token 2"], "priority": "high", "notification": { "title": "Divine Public School", "body": "Test Message." } } Header { "Content-Type: application/json", "Authorization: key=<myServerKey>" } I am getting status code 200 and even receiving notification in client app when hitting this url from Postman. But when I am trying to do the same in android using retrofit , I am getting status 400 Bad Request.

Retrofit response returning null in Android

China☆狼群 提交于 2020-05-25 07:03:07
问题 I wanted to display a text from a JSON value. I'm using Retrofit to make API call I don't know if I'm doing it right. Anyway here's my code. Here's the url link: http://api.icndb.com/jokes/random . The website will display a random joke each time. Here's the example of an output from the website: { "type": "success", "value": { "id": 175, "joke": "When Chuck Norris was a baby, he didn't suck his mother's breast. His mother served him whiskey, straight out of the bottle.", "categories": [] } }

Retrofit response returning null in Android

空扰寡人 提交于 2020-05-25 07:02:34
问题 I wanted to display a text from a JSON value. I'm using Retrofit to make API call I don't know if I'm doing it right. Anyway here's my code. Here's the url link: http://api.icndb.com/jokes/random . The website will display a random joke each time. Here's the example of an output from the website: { "type": "success", "value": { "id": 175, "joke": "When Chuck Norris was a baby, he didn't suck his mother's breast. His mother served him whiskey, straight out of the bottle.", "categories": [] } }

Retrofit response returning null in Android

醉酒当歌 提交于 2020-05-25 07:02:08
问题 I wanted to display a text from a JSON value. I'm using Retrofit to make API call I don't know if I'm doing it right. Anyway here's my code. Here's the url link: http://api.icndb.com/jokes/random . The website will display a random joke each time. Here's the example of an output from the website: { "type": "success", "value": { "id": 175, "joke": "When Chuck Norris was a baby, he didn't suck his mother's breast. His mother served him whiskey, straight out of the bottle.", "categories": [] } }

Send complex object using Retrofit2

别说谁变了你拦得住时间么 提交于 2020-05-17 07:43:05
问题 I'm trying to send a complex object as a parameter of my request using Retrofit2 and Kotlin. Structure of that object is the following: { "id": "..." "token": "..." "message": "..." "list1": [ { "id": 1, "value": 2 }, { "id": 2, "value": 5 } //and so on... ] "list2": [ { "id": 10, "value": 16 }, { "id": 11, "value": 21 } //and so on... ] //and so on... } The number of list fields is various (could be 2 lists, could be 10) as well as the number of items inside each list. I'm using the

OKhttp PUT example

强颜欢笑 提交于 2020-05-11 04:08:48
问题 My requirement is to use PUT , send a header and a body to server which will update something in the database. I just read okHttp documentation and I was trying to use their POST example but it doesn't work for my use case (I think it might be because the server requires me to use PUT instead of POST ) . This is my method with POST : public void postRequestWithHeaderAndBody(String url, String header, String jsonBody) { MediaType JSON = MediaType.parse("application/json; charset=utf-8");