0

I'm totally desperate trying to do this. I Started a new job where I was given an app made in Processing and now I need it to call a simple index.html(https://west-4f2bc.firebaseapp.com) but not opening it on the browser.

Is there anyway to do it? later I'm going to pass data adding parameters in URL but now I just need to call it as it is without a window opening.

Please Help me..... I tried a lot of variants of this code

import processing.net.*; 
Client myClient; 

void setup() { 
  // Connect to the local machine at port 10002.
  // This example will not run if you haven't
  // previously started a server on this port.
  myClient = new Client(this, "west-4f2bc.firebaseapp.com", 80); 
  // Say hello
  myClient.write("GET /\r\n");
} 

void draw() { 

}  

Thanks.

With this I only get true, so it connects but I only get 0.

import processing.net.*; 

Client myClient; 
int dataIn; 

void setup() { 
  size(200, 200); 
  // Connect to the local machine at port 5204.
  // This example will not run if you haven't
  // previously started a server on this port.
  myClient = new Client(this, "west-4f2bc.firebaseapp.com", 80); 
  println(myClient.active());
  println(dataIn);
} 

void draw() { 

} 

with this I get connected but after Client SocketException: Socket closed

import processing.net.*; 

Client myClient; 
int dataIn; 

void setup() { 
  Client client;
  client = new Client(this, "west-4f2bc.firebaseapp.com", 80);

  if (client.active()==true) {
    println("connected");
    // Make a HTTP request:
    client.write("GET /call.html?id=ola&nome=artur\r\n");
    client.write("\r\n");
    client.stop();
  } else {
    // if you didn't get a connection to the server:
    println("connection failed");
  }
} 
Cœur
  • 37,241
  • 25
  • 195
  • 267

2 Answers2

1

I've never really used Processing's Networking library, but from what I can tell it's not usually used to read data from a website- it's used for lower-level communication between a client and server. It might be possible to use it to read a website, but what you have already looks more complicated than it has to be.

Remember that Processing is built on top of Java, so anything you can do in Java, you can do in Processing. If I were you, I would do a google search for "java read website" for a ton of results, including:

Kevin Workman
  • 41,537
  • 9
  • 68
  • 107
  • I don't read the website. I just want to call it without open the page. To send parameters later. Like www.example.com/?Id=something&name=something and then pass that value to variables – Ricardo Rodrigues Jun 12 '18 at 17:21
  • @RicardoRodrigues The process is the same. Google something like "java post to url" for a ton of results. – Kevin Workman Jun 12 '18 at 19:12
0

I used another library.

import http.requests.*;

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

void draw()
{
  PostRequest post = new PostRequest("https://"+"www.example.com");                             

  post.send();

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

  noLoop();
}

Still doesnt does my final objective but at least it can communicate with the page.