简体   繁体   English

如何将 flutter 移动应用程序连接到 rest API 中托管在 Z3115FB34DFCB5BA87AA049707C596 中的节点 js 中?

[英]How to connect a flutter mobile app to a rest API in node js which is hosted in heroku?

I have deployed a rest API (nodejs) in Heroku but i want to know how to connect my flutter mobile app with these endpoints.I have looked for solution but i haven't seen anything regarding this.my flutter app is running in my mobile device.Hope any one can give a good solution. I have deployed a rest API (nodejs) in Heroku but i want to know how to connect my flutter mobile app with these endpoints.I have looked for solution but i haven't seen anything regarding this.my flutter app is running in my mobile设备。希望任何人都可以提供一个好的解决方案。

import 'package:http/http.dart' as http;

First import http package do mention that in pubspec,yaml then Import convert package if you want to deal with jsondata First import http package do mention that in pubspec,yaml then Import convert package if you want to deal with jsondata

import 'dart:convert';

Now you will be creating future functions for get request:现在您将为获取请求创建未来的函数:

Future<void> getGoodRequest1() async{
    var url = 'your url';
    http.Response response = await http.get(url);
    String data = response.body;
    
    print(jsonDecode(data));
    

  }

for post request发帖请求

Future<void> postGoodRequest2() async{

String url = 'your url';
Map<String, String> headers = {"Content-type": "application/json"};
// if you want to pass json along with it
    String json = '{"query": "example", "data": "example"}';
    // make POST request
    http.Response response = await http.post(url, headers: headers, body: json);
    // check the status code for the result
    print('posted');

  }

For more you can refer here Http flutter有关更多信息,您可以参考这里Http flutter

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将Node JS API与Flutter APP集成? - How to integrate Node JS API with Flutter APP? Send ZIP file to a REST based API which is using SSL TLS (https) hosted on AWS from a flutter based mobile application - Send ZIP file to a REST based API which is using SSL TLS (https) hosted on AWS from a flutter based mobile application flutter web:如何连接到 rest API 或 localhost - flutter web: how to connect to a rest API or localhost Messagebird SMS 身份验证/OTP 用于具有节点 js 和 flutter 的移动应用程序 - Messagebird SMS authentication/ OTP for mobile app with node js and flutter 在开发 flutter 应用程序时从手机调用节点 api - Call node api from mobile phone while developing flutter app 如何将 API 连接到由 Flutter 制作的应用程序? - How to connect an API to a app made from flutter? 如何将 flutter 应用程序与 socket.io 与 node.js 一起使用? - How to connect flutter app with socket.io used with node.js? 如何将Flutter应用程序与Node.js集成 - How to integrate flutter app with node.js 如何在 Flutter 手机应用程序中使用 JS 库和 JS function? - How to use a JS library and a JS function in a Flutter mobile app? Flutter: How to move a firebase node - API REST vs SDK - Flutter: How to move a firebase node - API REST vs SDK
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM