【问题标题】:How to use network frameworks (volley , okhttp , etc) in libgdx?如何在 libgdx 中使用网络框架(volley、okhttp 等)?
【发布时间】:2015-07-22 12:04:45
【问题描述】:

我想在 libgdx 中使用 volley 或 okhttp 从 Web 加载一些数据。
如何在 libgdx 中使用 volley 或 okhttp 等网络框架而不是 libgdx networking class

【问题讨论】:

    标签: android libgdx android-volley okhttp


    【解决方案1】:

    例如尝试将此compile 'com.squareup.okhttp:okhttp:2.3.0' 添加到您的项目build.gradle 文件中

    project(":core") {
        apply plugin: "java"
    
    
        dependencies {
                ...
                compile 'com.squareup.okhttp:okhttp:2.3.0'
            }
        }
    

    然后你可以在你的核心项目中使用 okhttp 这里是一个例子:

    public class OkhttpTest extends ApplicationAdapter {
        OkHttpClient client = new OkHttpClient();
    
        @Override
        public void create() {
            try {
                System.out.println(run("http://google.com"));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    
        String run(String url) throws IOException {
            Request request = new Request.Builder()
                    .url(url)
                    .build();
    
            Response response = client.newCall(request).execute();
            return response.body().string();
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-09
      相关资源
      最近更新 更多