使用齐射将承载令牌发送到服务器[关闭]

问题描述 投票:0回答:1

我想向承载服务器发送承载令牌,以证明该请求由我们的设备执行,并且只能将数据返回给我们。我正在使用齐射,但无法将承载令牌发送到服务器。

android okhttp
1个回答
-1
投票

您可以使用Okhttps发送“承载者令牌”。凌空不能执行此任务。

第一步:-

Add okhttps dependency in gradle file

implementation("com.squareup.okhttp3:okhttp:4.2.1") //if you want to use okhttps to run below android 5.0 use the version 3.11.0

第二步骤:-

Add "Authorization" in addHeader() and then you can send Bearer Token

final OkHttpClient client = new OkHttpClient();

okhttp3.Request request = new okhttp3.Request.Builder()
                .url(myurl)
                .get() //You can use post if you want to send some data
                .addHeader("Authorization", token)
                .build();


    client.newCall(request).enqueue(new Callback() {

        @Override
        public void onFailure(Call call, IOException e) {
            Log.e(TAG, "onFailure: ", e);
        }

        @Override
        public void onResponse(Call call, final okhttp3.Response response) throws IOException {
            final String data = response.body().string();

            Log.d(TAG, "Requestdata: " + data);


        }
    });

它会很好用,我个人正在使用它。。

© www.soinside.com 2019 - 2024. All rights reserved.