【问题标题】:Calling a webpage without opening it from processing调用网页而不从处理中打开它
【发布时间】:2018-06-12 16:08:55
【问题描述】:

我完全绝望地尝试这样做。我开始了一份新工作,我得到了一个在 Processing 中制作的应用程序,现在我需要它来调用一个简单的 index.html(https://west-4f2bc.firebaseapp.com) 但不能在浏览器上打开它。

有什么办法吗? 稍后我将在 URL 中传递数据添加参数,但现在我只需要在没有打开窗口的情况下调用它。

请帮帮我..... 我尝试了很多此代码的变体

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() { 

}  

谢谢。

有了这个,我只得到真实的,所以它连接但我只得到 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() { 

} 

这样我就可以连接了,但是在 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");
  }
} 

【问题讨论】:

    标签: java firebase client-server processing


    【解决方案1】:

    我从未真正使用过 Processing 的网络库,但据我所知,它通常不用于从网站读取数据——它用于客户端和服务器之间的低级别通信。或许可以用它来阅读网站,但你已经看到的东西比它必须的要复杂。

    请记住,Processing 是建立在 Java 之上的,因此您可以在 Java 中执行的任何操作,都可以在 Processing 中执行。如果我是你,我会在谷歌上搜索“java read website”以获得大量结果,包括:

    【讨论】:

    • 我不看网站。我只想在不打开页面的情况下调用它。稍后发送参数。比如 www.example.com/?Id=something&name=something 然后将该值传递给变量
    • @RicardoRodrigues 过程是一样的。谷歌诸如“java post to url”之类的搜索结果。
    【解决方案2】:

    我使用了另一个库。

    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();
    }
    

    仍然没有达到我的最终目标,但至少它可以与页面通信。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-20
      • 2012-01-04
      • 2018-01-27
      相关资源
      最近更新 更多