민프

[Flutter] http 통신 GET,POST해보기 본문

[Flutter]

[Flutter] http 통신 GET,POST해보기

민프야 2023. 1. 9. 19:00

POST

http.Response response = await http.post(
      url,
      headers: <String, String> {
        'Content-Type': 'application/json',
      },
      body: text,
    );

GET을 할때 body에 데이터를 넣어야할때에도 있는데

이때에는 url에 아래와 같이 쿼리파라미터로 넣어줘야 한다. 

final newURI = uri.replace(queryParameters: params);
or
final newURI = Uri.http('www.example.com', '/path', queryParameters);



http.Response response = await http.get(
      newURI,
      headers: <String, String> {
        'Content-Type': 'application/json',
      },
    );
Comments