flutter_测试网络

import 'dart:convert';

// import 'package:dio/dio.dart';
// import 'package:pupilmath_web/datamodel/exercise_entity_list.dart';
// import 'package:pupilmath_web/datamodel/exercise_result_data_model.dart';
// import 'package:pupilmath_web/datamodel/push_exercise_response.dart';
// import 'package:pupilmath_web/entity_factory.dart';
// import 'package:pupilmath_web/my/httprequest.dart';
// import 'package:pupilmath_web/network/constant.dart';
// import 'package:pupilmath_web/network/network.dart';
// import 'package:pupilmath_web/viewmodel/exercise/viewmodel_base_multi_exercise.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;


var responseBody;   

void main()async{
  // String _url = '$exerciseUrl/$exerciseId/questions';

    String testUrl = "http://pupilsandbox.inner.youdao.com/ypm-web/exercise/C15B1EBE688C461BA2BE60453139ED5A/questions";

    var params = Map<String, String>();
    params["levelNum"] = "2";

    var body = json.encode({"levelNum": "2"});

    var client = http.Client();  
    var response = await client.post(testUrl,headers: {
      "content-type" : "application/json",
    }, body: body).then((response){
      responseBody = response.body;  
      print(response.body);  
    });

//    _content = response.body;
    // printHelper("response::" + response.body.toString());
    runApp(MyApp());
}


class MyApp extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: Text("hello"),),
        body: Text(responseBody!=null?responseBody:"空"),)
    );  
  }
}
此条目发表在未分类分类目录。将固定链接加入收藏夹。

发表评论

电子邮件地址不会被公开。 必填项已用*标注