1

Hello I am having a problem. I am using Volley to request to https://swapi.dev/

RequestQueue queue = Volley.newRequestQueue(this);
StringRequest request = new StringRequest(Request.Method.GET,
     "http://swapi.dev/api/planets/1/",
     System.out::println,
     null);
queue.add(request);

Then Volley throws an exception:

E/Volley: [53530] BasicNetwork.performRequest: Unexpected response code 301 for http://swapi.dev/api/planets/1/

Please help

Ryan M
  • 18,333
  • 31
  • 67
  • 74
  • Use in url "https://..." doesn't work – Игорь Старк Aug 04 '20 at 21:54
  • You are requesting `http://swapi.dev...` and the webserver at that address is returing a 301. This is a response indicating that the website has moved to `https://swapi.dev`. Changing the URL string in line 3 of your example to start with `https` rather than `http` will fix this issue. I've just done this in my browser, and can confirm that it works. Can you share some any error messages you receive when using https? – Jamie Taylor Aug 04 '20 at 22:58

1 Answers1

-1

You are using this url:

http://swapi.dev/api/planets/1/

Enable "ClearText" compatibility to allow connections using http: , this must be done inside your AndroidManifest.xml file:

   <application
        ...
        ....
        android:usesCleartextTraffic="true"
        ...
        ...

Is recommended to use only https:// like https://swapi.dev/api/planets/1/

Jorgesys
  • 124,308
  • 23
  • 334
  • 268