Reputation: 19
I have a problem using Node.js. I am sending data via GET request to special script, which should read this data and write it in MySQL. Here is an example of GET request (very long):
http://demo.com/?&bssid=16~6D~57~7F~D8~AD&mac=60~01~94~2B~A8~85&rssi=0&hotspots_list=~~0_74~85~2A~39~77~48_-85~~~~1_78~8C~54~33~D8~3C_-91~~~
~2_64~6E~EA~0E~B3~26_-84~~~~3_76~85~2A~39~77~49_-87~~~~4_2C~33~7A~16~91~3B_-92~~~~5_54~BE~F7~6B~EE~43_-92~~~~6_98~DE~D0~AB~B8~64_-91~~~~7_14~DD~A9~1E
~F6~F8_-93~~~~8_64~6E~EA~0C~9A~3E_-84~~~~9_E8~DE~27~50~2A~12_-88~~~~10_84~C9~B2~0B~BA~C2_-81~~~~11_00~0F~94~BE~FC~44_-87~~~~12_56~BE~F7~6B~EE~44_-86~
~~~13_00~0E~8F~85~5F~73_-53~~~~14_0C~54~A5~A6~C1~1F_-87~~~~15_16~6D~57~7F~D8~AD_-78~~~~16_0E~54~A5~A6~C1~10_-92~~~~0_EC~1A~59~17~CF~5F_-91~~~~1_74~85
~2A~39~77~48_-92~~~~2_16~6D~57~7F~D8~AD_-77~~~~3_0C~54~A5~A6~C1~1F_-92~~~~4_0E~54~A5~A6~C1~10_-83~~~~5_84~C9~B2~0B~BA~C2_-82~~~~6_14~DD~A9~1E~F6~F8_-
92~~~~7_64~6E~EA~0C~9A~3E_-85~~~~8_E8~DE~27~50~2A~12_-93~~~~9_00~22~6B~56~2B~83_-92~~~~10_00~0E~8F~85~5F~73_-58~~~~11_00~0F~94~DB~DE~64_-91~~~~12_16~
DD~A9~1E~F6~F9_-92~~
I've done few experiments, and I found out, that it works fine in PHP, my code (only for output):
<?php
echo $_GET["bssid"]." ".$_GET["mac"]." ".$_GET["rssi"]." ".$_GET["hotspots_list"];
?>
But not in Node.js !This is my Node.js code:
var express = require("express");
var app = express();
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'host',
user : 'user',
password : 'pswd',
database : 'db'
});
var bssid, mac, rssi, hotspots_list;
const port = 3000;
const host = "0.0.0.0";
app.get('/', function (request, response) {
//Writing data to vars
bssid = request.query.bssid;
mac = request.query.mac;
rssi = request.query.rssi;
hotspots_list = request.query.hotspots_list;
//Sending request to MySQL server
connection.query(`INSERT INTO locations (mac, bssid_current, rssi_currnet, hotspots_list) VALUES ('${mac}','${bssid}','${rssi}','${hotspots_list}')`);
//Debugging line
console.log(`BSSID: ${bssid}`);
//Response
response.statusCode = 200;
response.setHeader('Content-Type', 'text/plain');
return response.send('Done');
});
app.listen(port, host, () => {
console.log(`Server running!`);
});
Upvotes: 0
Views: 35
Reputation: 1226
In your code, your route is /
. And you are trying to access it via /server.js
Two solutions, either you add
app.get('/server.js', [...])
or you access it after removing server.js
from your url.
Upvotes: 1