Answer the question
In order to leave comments, you need to log in
How to send a simple post request in a Kotlin class?
Firebase cloud messaging is connected in the application. There is a kotlin class that displays the device token.
package com.placeholder
import android.util.Log
import com.google.firebase.messaging.FirebaseMessagingService
import android.util.Log.d as d1
class MyFirebaseMessagingService : FirebaseMessagingService(){
override fun onNewToken(token: String) {
d1("TAG", "The token refreshed: $token")
}
}
Answer the question
In order to leave comments, you need to log in
Specifically, in the class - xs, but Postman has a code generator for requests (though in Java)
times
Unirest.setTimeouts(0, 0);
HttpResponse response = Unirest.post(" http://host.ru:80/user/register ")
.header("Content-Type", "text/plain")
.body("{\n \"firstName\" : \"Conso\",\n \"insertToTestClient\": false,\n \"investEmailDomain\": true,\n \"isLegal\": false,\n \"lastName\": \"Barsukov\" ,\n \"middleName\": \"Medoedovich\"\n}")
.asString();
two
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("
RequestBody body = RequestBody.create(mediaType, "{\n \"firstName\": \"Conso\",\n \"insertToTestClient\": false,\n \"investEmailDomain\": true,\n \"isLegal \": false,\n \"lastName\": \"Barsukov\",\n \"middleName\": \"Medoedovich\"\n}");
Request request = new Request.Builder()
.url(" http://host.ru:80/user/register ")
.method("POST", body)
.addHeader("Content-Type", "text/plain ")
.build();
Response response = client.newCall(request).execute();
just plug it in where you want it and it works. and there it is possible to spread the variables and wrap them as needed.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question