I found a solution or at least part of the solution. The project is for fun but its turning out to be more complicated than originally expected and this is just the basic part.
What I did was to:
1)install greasemonkey addon for firefox. There is an equivalent for chrome
2)install flask
Then I wrote a script in greasemonkey. Again, probably not the greates code but, I'm sure it will help someone somewhere.
// ==UserScript==
// @name js send data experiment
// @version 1
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @grant GM.xmlHttpRequest
// ==/UserScript==
let data = [
{"who":"greasemonkey", "what":"Hi there4"}
];
GM.xmlHttpRequest({
method: "POST",
url: "http://localhost:5000/worker2",
data: JSON.stringify(data),
headers: {
"Content-Type": "application/x-www-form-urlencoded"
}
});
I'm not sure about needing the ajax but you definitely need the @grant GM.xmlHttpRequest
Then I wrote this python script, ran it in the command line and it all worked.
#!flask/bin/python
import sys
from flask import Flask, render_template, request, redirect, Response
import random, json
app = Flask(__name__)
@app.route('/worker2', methods = ['POST'])
def worker2():
# read json + reply
data = request.get_json(force=True)
print("**************** ")
print(data)
print("**************** ")
return "success!!!"
if __name__ == '__main__':
# run!
app.run(debug=True)