Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
332 views
in Technique[技术] by (71.8m points)

flutter - HTTP.get() hangs up

import 'package:http/http.dart';

import 'model_post.dart';

class PostService {
  Future<List<Post>> getPosts() async {
    print('DEBUGGING: x');
    //Response response = await get("https://jsonplaceholder.typicode.com/posts"); // Works fine.
    Response response = await get("https://delicate-river-096e.flutter-apps.workers.dev"); // Hangs up!!!
    print('Response status: ${response.statusCode}');
  }
}
Running "flutter pub get" in http_alex...
Launching lib/main.dart on Chrome in debug mode...
Waiting for connection from debug service on Chrome...
Debug service listening on ws://127.0.0.1:33451/q_w1rk9eLZk=/ws

Running with unsound null safety
For more information see https://dart.dev/null-safety/unsound-null-safety
Debug service listening on ws://127.0.0.1:33451/q_w1rk9eLZk=/ws


DEBUGGING: x

Hi,

The URL https://delicate-river-096e.flutter-apps.workers.dev returns exactly the same valid JSON copied from https://jsonplaceholder.typicode.com/posts.

Why does it not work?

I tried it with a lot of others hosts, but with the same result.

Very strang behavior. I despair, hope anybody can help me?

Thank you in advance.

Alex

question from:https://stackoverflow.com/questions/65889810/http-get-hangs-up

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
import 'package:http/http.dart' as http;


import 'model_post.dart';

class PostService {
  Future<List<Post>> getPosts() async {
    print('DEBUGGING: x');
    //Response response = await http.get("https://jsonplaceholder.typicode.com/posts"); // Works fine.
    Response response = await http.get("https://delicate-river-096e.flutter-apps.workers.dev"); // Hangs up!!!
    print('Response status: ${response.statusCode}');
  }
}

Change Your Code to this and Try Again it will Work Now


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...