Make an HTTP request with android

后端 未结 12 1365
时光取名叫无心
时光取名叫无心 2020-11-21 06:38

I have searched everywhere but I couldn\'t find my answer, is there a way to make a simple HTTP request? I want to request a PHP page / script on one of my websites but I do

12条回答
  •  生来不讨喜
    2020-11-21 07:15

    Look at this awesome new library which is available via gradle :)

    build.gradle: compile 'com.apptakk.http_request:http-request:0.1.2'

    Usage:

    new HttpRequestTask(
        new HttpRequest("http://httpbin.org/post", HttpRequest.POST, "{ \"some\": \"data\" }"),
        new HttpRequest.Handler() {
          @Override
          public void response(HttpResponse response) {
            if (response.code == 200) {
              Log.d(this.getClass().toString(), "Request successful!");
            } else {
              Log.e(this.getClass().toString(), "Request unsuccessful: " + response);
            }
          }
        }).execute();
    

    https://github.com/erf/http-request

提交回复
热议问题