Advertisement
Guest User

Untitled

a guest
Feb 25th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Net;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows.Forms;
  13.  
  14. namespace WindowsFormsApp15
  15. {
  16.     public partial class Form1 : Form
  17.     {
  18.         public class JsonResult
  19.         {
  20.             public int id { get; set; }
  21.             public string name { get; set; }
  22.         }
  23.  
  24.        
  25.  
  26.  
  27.         public Form1()
  28.         {
  29.             InitializeComponent();
  30.  
  31.  
  32.             string html = string.Empty;
  33.             string url = @"http://localhost:8080/users";
  34.  
  35.             HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  36.             request.AutomaticDecompression = DecompressionMethods.GZip;
  37.  
  38.             using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
  39.             using (Stream stream = response.GetResponseStream())
  40.             using (StreamReader reader = new StreamReader(stream))
  41.             {
  42.                 html = reader.ReadToEnd();
  43.             }
  44.  
  45.             //Console.WriteLine(html);
  46.  
  47.  
  48.             label1.Text = html;
  49.  
  50.             var result = JsonConvert.DeserializeObject<List<JsonResult>>(html);
  51.             dataGridView1.DataSource = result;
  52.         }
  53.  
  54.         private void label1_Click(object sender, EventArgs e)
  55.         {
  56.  
  57.         }
  58.     }
  59. }
  60. var mysql = require('mysql');
  61.  
  62. var express = require('express')
  63. var app = express()
  64.  
  65. var con = mysql.createConnection({
  66.   host: "localhost",
  67.   user: "root",
  68.   password: "",
  69.   database: "experiment"
  70. });
  71. /*
  72. con.connect(function(err) {
  73.   if (err) throw err;
  74.   console.log("Connected!");
  75. });
  76. */
  77. con.connect(function(err) {
  78.   if (err) throw err;
  79.   console.log("Connected!");
  80.   con.query("SELECT * FROM users", function (err, result) {
  81.     if (err) throw err;
  82.     console.log("Result: " + result);
  83.    
  84.     var len = result.length;
  85.     for ( var i = 0; i < len; i++ ){
  86.         console.log(result[i].name)
  87.     }
  88.    
  89.     app.get('/', function (req, res) {
  90.   res.send('hello world')
  91. })
  92.  
  93.     app.get('/users', function (req, res) {
  94.       //res.write('connected!\n');
  95.       /*
  96.         for ( var i = 0; i < len; i++ ){
  97.             res.write(result[i].name + '\n')
  98.         }
  99.         */
  100.        
  101.         //https://www.nuget.org/packages/Newtonsoft.Json/6.0.3
  102.        
  103.         res.setHeader('Content-Type', 'application/json');
  104.         res.write(JSON.stringify(result))
  105.         res.end()
  106. })
  107.     /*
  108.     http.createServer(function (req, res) {
  109.       res.writeHead(200, {'Content-Type': 'text/plain'});
  110.       res.write('connected!\n');
  111.      
  112.         for ( var i = 0; i < len; i++ ){
  113.             res.write(result[i].name + '\n')
  114.         }
  115.      
  116.       res.end();
  117.     }).listen(8080);
  118.     */
  119.    
  120.     app.listen(8080, () => console.log(`Example app listening on port ${8080}!`))
  121.     //con.end()
  122.    
  123.   });
  124. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement