Flutter 학습(네트워크 요청)

664 단어 Flutter
//TODO:    
import 'dart:convert';
import 'dart:io';
//TODO:   get post put delete
var httpClient = new HttpClient();
class A {
  //  asy get   
  get() async{
    var responseBody;
    var url='http://www...';
    var httpClient = new HttpClient();
    var request = await httpClient.getUrl(Uri.parse(url));
    var response = await request.close();
    if (response.statusCode == 200) {
      responseBody = await response.transform(utf8.decoder).join();
      responseBody=jsonDecode(responseBody);
      print(responseBody['data']['records']);
    }else{
      print("error");
    }
  }
}

좋은 웹페이지 즐겨찾기