【问题标题】:Secure and easy transfer of MySql data from server to clientMySql 数据从服务器到客户端的安全和轻松传输
【发布时间】:2014-01-30 11:16:14
【问题描述】:

我的服务器端应用程序中有一块 Dart,我不知道如何将 MySql 传递的地图转换为 JSON 类型的结构,以将这些数据发送到客户端。
安全:无法进行 Sql 注入;
简单:只需几行代码即可转换数据,考虑到字符串包含字符串分隔符(' 或 "),不允许简单的连接。
在客户端上,我解码一个 JSON 字符串并填充表单。 这是服务器例程:

 void handlePost(HttpRequest req) {
   HttpResponse res = req.response; 
    req.listen((List<int> buffer) {
     addCorsHeaders(res);  
     AsciiDecoder a = new AsciiDecoder();
     String s = a.convert(buffer); // contains key data in JSON-string
     Map data = JSON.decode(s);
     if (data.containsKey("key")){
       var r1 = data{"key"};      
       pool.query('select fi, la, age from person where keyT =' + r1).then((result) {
         result.forEach((row) {
             print("FirstName: ${row[0]}, lastName: ${row[1]}, Age: ${row[2]}");
             closeRes(res, JSONdata);
         });
       });
     }
     else closeRes(res, "NOK missing key");
   },
   onError: printError);
 }

我在哪里写print("FirstName: ${row[0]}, lastName: ${row[1]}, Age: ${row[2]}");
我会编写一些将 MySql 映射转换为某种东西的代码,我可以在客户端将其转换为 JSON 某种东西。 在客户端我有这个:

 void getDataFromServer(){
   HttpRequest request = new HttpRequest(); // create a new XHR  
   request.onReadyStateChange.listen((_) {
     if (request.readyState == HttpRequest.DONE &&
        (request.status == 200 || request.status == 0)) {
       extractJson(request.responseText); // output the response 
     }
   });  
   request.open("POST", url, async: false);
   request.send(jsonData); // POST string like: {"key":"12345"}
 }

有人可以写几行代码,显示操作方法吗?或者给我看一篇有一些工作例子的文章?我正在运行最新版本的 Dart。
我曾经(15 年)用 VBasic 编写桌面应用程序,现在尝试转换。

【问题讨论】:

  • 我认为您需要的一切都在 StackOverflow 上。只需使用搜索功能。 “给我一些代码”问题与 SO 无关。
  • 如果是这样,请重新阅读我的问题:什么 DART 例程可以将 SqlJocky 返回的 MySql 映射转换为 Jason-map。
  • 为了安全传输,请使用 SSL 加密。
  • 从某种意义上说是安全的,我不上传 html 注入类型的数据。我找不到任何可以转换 &things; 中所有特殊字符的例程(例如在 php 中)
  • Dart 在没有验证器的情况下自动清理插入到页面中的任何 html 内容。也许它对用户输入也是如此。我需要检查一下。

标签: json webserver dart dart-io


【解决方案1】:

stackoverflow 中找到了 JSON 编码的解决方案。将类中描述sql-table的所有字段设置为mysql得到的结果并序列化。连接所有行。然后将字符串传递给客户端。

等待 Nawaf Alsulami 回答问题的注入部分

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-09
    • 1970-01-01
    相关资源
    最近更新 更多