将HTTP请求从Processing发布到网站

时间:2018-06-13 15:00:49

标签: javascript java html post https

我有一个页面,当有人访问它时,它会将数据保存在Firestore数据库的URL上。但我需要从处理中访问它而不打开它。

我使用link(https://west-4f2bc.firebaseapp.com/call.html?id=5854&nome=Ricardo&pron=31&supi=22&fle=39&ext=23&rad=12&uln=18&age=28&gen=M&job=Investigador&hand=Right1Hand&pat=)查看它是否有效并且效果很好。

但就像我说的那样,我需要它才能在不打开页面的情况下工作。 我试过了

import http.requests.*;

void setup()
{
  size (100, 100);
}

void draw()
{
  PostRequest post = new PostRequest("https://"+"west-4f2bc.firebaseapp.com/app.js?id=5857&nome=Ricardo&pron=31&supi=22&fle=39&ext=23&rad=12&uln=18&age=28&gen=M&job=Investigador&hand=Right1Hand&pat=");                             
  post.addHeader("username", "username");                                                                                         
  post.addHeader("password", "password");
  post.send();

  System.out.println("Reponse Content: " + post.getContent());
  System.out.println("Reponse Content-Length Header: " + post.getHeader("Content-Length"));

  noLoop();
}

它打印页面代码,因此它可以访问它但不保存数据库中的URL参数。

我应该添加或更改什么? 感谢。

HTML

    <!DOCTYPE html>

<html>
    <head>
        <meta charset="utf-8">
        <title>Hot Dogs</title>

        <script src="https://www.gstatic.com/firebasejs/4.12.1/firebase.js"></script>
        <script src="https://www.gstatic.com/firebasejs/4.12.1/firebase-firestore.js"></script>

    </head>
    <body>

        <h1 id="hotDogOutput">Hot dog Status: </h1>
        <input type="textfield" id="idPatient" />
        <!--<input type="textfield" id="latestHotDogStatus" />-->
        <button id="saveButton">Save</button>
        <script src="./app.js"></script>

    </body>
</html>

JS

//function(){
    //initialize Firebase
          // Initialize Firebase

          var config = {
            apiKey: "AIzaSyDQSvOivHB9dEDsYz9fSe9IHrsBP2YpbUU",
            authDomain: "west-4f2bc.firebaseapp.com",
            databaseURL: "https://west-4f2bc.firebaseio.com",
            projectId: "west-4f2bc",
            storageBucket: "west-4f2bc.appspot.com",
            messagingSenderId: "418043077814"
          };
          firebase.initializeApp(config);
          var firestore=firebase.firestore();

          function getAllUrlParams(url) {

  // get query string from url (optional) or window
  var queryString = url ? url.split('?')[1] : window.location.search.slice(1);

  // we'll store the parameters here
  var obj = {};

  // if query string exists
  if (queryString) {

    // stuff after # is not part of query string, so get rid of it
    queryString = queryString.split('#')[0];

    // split our query string into its component parts
    var arr = queryString.split('&');

    for (var i=0; i<arr.length; i++) {
      // separate the keys and the values
      var a = arr[i].split('=');

      // in case params look like: list[]=thing1&list[]=thing2
      var paramNum = undefined;
      var paramName = a[0].replace(/\[\d*\]/, function(v) {
        paramNum = v.slice(1,-1);
        return '';
      });

      // set parameter value (use 'true' if empty)
      var paramValue = typeof(a[1])==='undefined' ? true : a[1];

      // (optional) keep case consistent
      //paramName = paramName.toLowerCase();
      //paramValue = paramValue.toLowerCase();

      // if parameter name already exists
      if (obj[paramName]) {
        // convert value to array (if still string)
        if (typeof obj[paramName] === 'string') {
          obj[paramName] = [obj[paramName]];
        }
        // if no array index number specified...
        if (typeof paramNum === 'undefined') {
          // put the value on the end of the array
          obj[paramName].push(paramValue);
        }
        // if array index number specified...
        else {
          // put the value at that index number
          obj[paramName][paramNum] = paramValue;
        }
      }
      // if param name doesn't exist yet, set it
      else {
        obj[paramName] = paramValue;
      }
    }
  }

  return obj;
}
    const id=getAllUrlParams().id; 
    const name=getAllUrlParams().nome; 
    const cage=getAllUrlParams().age; 
    const cgen=getAllUrlParams().gen;
    const cjob=getAllUrlParams().job; 
    const cpat=getAllUrlParams().pat;
    const chan=getAllUrlParams().hand;
    const chand=chan.replace('1',' ');
    const cpron=getAllUrlParams().pron; 
    const csupi=getAllUrlParams().supi;
    const cfle=getAllUrlParams().fle; 
    const cext=getAllUrlParams().ext;
    const crad=getAllUrlParams().rad; 
    const culn=getAllUrlParams().uln;

        firestore.collection("/Clinicas/FEUP/Pacientes/"+ id +"/"+ "Pronation/").get().then(function(querySnapshot) {      
    console.log(querySnapshot.size); 
    var size= querySnapshot.docs.length+1;
    var i = size+1;
    const docRef0 = firestore.doc("/Clinicas/FEUP/Pacientes/"+ id +"/");
              console.log("I am going to save " + id + i +" Data to Firestore");
              docRef0.set({ 
              Name: name,Clinic: "FEUP",Age:cage,Gender:cgen,Job:cjob,Patology:cpat}).then(function(){
              console.log("Status Save");
              }).catch(function(error) {console.log("Got an error: ", error);});

                const docRef = firestore.doc("/Clinicas/FEUP/Pacientes/"+ id +"/"+ "Pronation/"+ i);
              console.log("I am going to save " + id + i +" Pronation to Firestore");
              docRef.set({
    Hand: chand,
    Test: "Evaluation",
        value: cpron
              }).then(function(){
                  console.log("Status Save");
              }).catch(function(error) {
                    console.log("Got an error: ", error);
                });
                const docRef2 = firestore.doc("/Clinicas/FEUP/Pacientes/"+ id +"/"+ "Supination/"+ i);
              console.log("I am going to save " + id + i +" Supination to Firestore");
              docRef2.set({
    Hand: chand,
    Test: "Evaluation",
        value: csupi
              }).then(function(){
                  console.log("Status Save");
              }).catch(function(error) {
                    console.log("Got an error: ", error);
                });

                const docRef3 = firestore.doc("/Clinicas/FEUP/Pacientes/"+ id +"/"+ "Flexion/"+ i);
              console.log("I am going to save " + id + i +" Flexion to Firestore");
              docRef3.set({
    Hand: chand,
    Test: "Evaluation",
        value: cfle
              }).then(function(){
                  console.log("Status Save");
              }).catch(function(error) {
                    console.log("Got an error: ", error);
                });

                const docRef4 = firestore.doc("/Clinicas/FEUP/Pacientes/"+ id +"/"+ "Extension/"+ i);
              console.log("I am going to save " + id + " Extension to Firestore");
              docRef4.set({
    Hand: chand,
    Test: "Evaluation",
        value: cext
              }).then(function(){
                  console.log("Status Save");
              }).catch(function(error) {
                    console.log("Got an error: ", error);
                });
                const docRef5 = firestore.doc("/Clinicas/FEUP/Pacientes/"+ id +"/"+ "Radial/"+ i);
              console.log("I am going to save " + id + " Radial to Firestore");
              docRef5.set({
    Hand: chand,
    Test: "Evaluation",
        value: crad
              }).then(function(){
                  console.log("Status Save");
              }).catch(function(error) {
                    console.log("Got an error: ", error);
                });
                const docRef6 = firestore.doc("/Clinicas/FEUP/Pacientes/"+ id +"/"+ "Ulnar/"+ i);
              console.log("I am going to save " + id + " Ulnar to Firestore");
              docRef6.set({
    Hand: chand,
    Test: "Evaluation",
        value: culn
              }).then(function(){
                  console.log("Status Save");
              }).catch(function(error) {
                    console.log("Got an error: ", error);
                });
});

        /*const textToSave = inputTextField.value;
          const docRef = firestore.collection("/Clinicas/FEUP/Pacientes/"+ textToSave +"/"+ "Extension");*/

          const outputHeader = document.querySelector("#hotDogOutput");

          const saveButton = document.querySelector("#saveButton");

          //saveButton.addEventListener("click",function(){
                const inputTextField = document.querySelector("#idPatient");
                //const textToSave = inputTextField.value;
                const textToSave = "rt4rt";


            //})


//})();

0 个答案:

没有答案