0
点赞
收藏
分享

微信扫一扫

ubuntu xrdp远程登录一直弹出Authentication required. System policy prevents WiFi scans

静悠 2023-11-16 阅读 14

1.青云客

官网:http://api.qingyunke.com/
在这里插入图片描述

2.添加依赖

<!--okhttp3 依赖-->
        <dependency>
            <groupId>com.squareup.okhttp3</groupId>
            <artifactId>okhttp</artifactId>
            <version>4.9.3</version>
        </dependency>

        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.8.9</version>
        </dependency>
        <dependency>
            <groupId>com.vaadin.external.google</groupId>
            <artifactId>android-json</artifactId>
            <version>0.0.20131108.vaadin1</version>
        </dependency>

3.主程序

package org.example;


import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import okhttp3.OkHttpClient;
import okhttp3.Request;

import java.io.IOException;

public class reply {

    public static void main(String[] args) throws IOException {
        ok();
    }
    public static void ok(){
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    String data = "今天天气不错!";
                    String url = "http://api.qingyunke.com/api.php?key=free&appid=0&msg="+data;
                    OkHttpClient client = new OkHttpClient();
                    Request request = new Request.Builder().url(url).build();
                    okhttp3.Response response = client.newCall(request).execute();
                    if (response.isSuccessful()) {
                        assert response.body() != null;
                        System.out.println(response);

                        String re = response.body().string();

                        // 使用 JsonParser 解析字符串为 JsonObject
                        JsonObject jsonObject = JsonParser.parseString(re).getAsJsonObject();

                        // 获取 content 字段的值
                        String content = jsonObject.get("content").getAsString();

                        // 打印提取的内容
                        System.out.println("回答:"+content);
                    } else {
                        System.out.println("error");
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
}


4.返回结果

在这里插入图片描述

举报

相关推荐

0 条评论