2

Please check the code below, when I am trying to fetch https://cdn.pixabay.com/photo/2018/04/24/03/22/animal-3346192_150.jpg
I am getting a 403 response with the message: error code: 1010
It works when using okhttp3 library

    Net.HttpRequest httpRequest = new HttpRequestBuilder()
            .newRequest()
            .method(Net.HttpMethods.GET)
            .url(url)
            .build();

    Gdx.net.sendHttpRequest(httpRequest, new Net.HttpResponseListener() {

        @Override
        public void handleHttpResponse(Net.HttpResponse httpResponse) {
            final int statusCode = httpResponse.getStatus().getStatusCode();
            if (statusCode < 200 || statusCode > 300) {
                return;
            }

            ...
        }

        @Override
        public void failed(Throwable t) {
            callback.onFailure(t);
        }

        @Override
        public void cancelled() {
            callback.onCancel();
        }
    });
Ilya Gazman
  • 31,250
  • 24
  • 137
  • 216

1 Answers1

0

I had the same problem and solved it by adding User-Agent header:

request.setHeader(HttpRequestHeader.UserAgent, "hhh")
Hadi Ahmadi
  • 1,924
  • 2
  • 17
  • 38