1

In my browser it returns the correct json

http://localhost:8008/api/instsets/?genre=rock

Howeber in dart code

final response = await http.get(Uri.http('localhost:8008', 'api/instsets/?genre=rock'));

It returns 404 error.

Without query, it works,

final response = await http.get(Uri.http('localhost:8008', 'api/instsets'));

Where should I fix??

1
  • Do you get 404 from emulator/phone, or from same machine as browser? Commented Apr 11, 2021 at 11:32

4 Answers 4

1

According to flutter documentation, the query parameter should be an object and you should pass it to the function as the third argument. So in your case, the code will be:

final response = await http.get(Uri.http('localhost:8008', 'api/instsets', { genre: 'rock' }));
Sign up to request clarification or add additional context in comments.

1 Comment

It works!!! thank you very much. ?query=value doesn't work on http.get
0

It is because it is on your localhost

localhost = 127.0.0.1

You have to point your local IP address instead of localhost

ex: http://192.168.1.101:8008 like this.

In case of laravel api,

php artisan serve --host=192.168.1.101

1 Comment

That might not be the cause.
0

You included an extra / before your query.

You had 'api/instsets/?genre=rock'

Instead of 'api/instsets?genre=rock', which (I think) is also the same result as using the query object.

APIs (at least the ones I use) are sensitive to trailing /s

e.g. if you created a test-route, calling

  • api/v1/test-route would return 200
  • api/v1/test-route/ would return 404

Comments

0
final response = await http.get(Uri.parse('http://localhost:8008/api/instsets/?genre=rock'));

1 Comment

HI DiyorbekDev, can you explain a bit what your solution does? It may seem clear but less experienced users will profit from a short explanation (and the algorithm won't mark your answer as low-quality).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.