# Processing Network HTTP Request Help

**URL:** https://discourse.processing.org/t/processing-network-http-request-help/17069
**Category:** Libraries
**Created:** [January 13, 2020, 8:03pm UTC](https://discourse.processing.org/t/processing-network-http-request-help/17069 "2020-01-13T20:03:24Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![biran4454](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@biran4454](https://discourse.processing.org/u/biran4454)
#### Post date: [January 13, 2020, 8:03pm UTC](https://discourse.processing.org/t/processing-network-http-request-help/17069/1 "2020-01-13T20:03:24Z")

</div>

Hello!  
I have been creating a program in Processing Java to get the HTML of a site with HTTP GET in the [Networking Library](https://processing.org/reference/libraries/net/index.html). I followed the instructions in the [Processing Network Tutorial](https://processing.org/tutorials/network/), but it only shows how to get the HTML for one site, www.ucla.edu.  
I initially started this topic because I got a 400 Bad request code, but now I realize the documentation of the network library is not great, and I don’t have a clue how to redirect to a different site.  
The tutorial says I should use

```auto
Client c;
c = new Client(this, "www.ucla.edu", 80); // Connect to server on port 80 
c.write("GET / HTTP/1.0\n"); // Use the HTTP "GET" command to ask for a webpage
c.write("Host: www.ucla.edu\n\n"); // Tell the server for which domain you are making the request

```

but I can’t use this to connect to other sites or pages.  
Does anyone know the way to connect to other sites?  
Thanks and sorry this is really badly worded…

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [January 14, 2020, 2:54am UTC](https://discourse.processing.org/t/processing-network-http-request-help/17069/2 "2020-01-14T02:54:34Z")

</div>

Try examples here:

> **[processing/processing](https://github.com/processing/processing/tree/master/java/libraries/net/examples)**
>
> Source code for the Processing Core and Development Environment (PDE) - processing/processing

🙂

---

<div class="post-metadata">

### Author: ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)
#### Post date: [January 14, 2020, 4:26am UTC](https://discourse.processing.org/t/processing-network-http-request-help/17069/3 "2020-01-14T04:26:14Z")

</div>

Please share your attempts and your efforts.

I have found a couple of post from previous posts:

- [https://forum.processing.org/two/discussion/15978/sending-a-http-get-request](https://forum.processing.org/two/discussion/15978/sending-a-http-get-request)
- [https://forum.processing.org/two/discussion/22202/http-request](https://forum.processing.org/two/discussion/22202/http-request)

Below is an example using HTTP GET / and using `loadString()`. The value of **OUTPUT\_LEN** defines the amount of data to output in the console.

Kf

```java
//REFERENCES: Text only websites https://sjmulder.nl/en/textonly.html

//===========================================================================
// IMPORTS:
import http.requests.*;

//===========================================================================
// FINAL FIELDS:
final int OUTPUT_LEN=150;
final String[] urls = {
  "http://www.example.com/", 
  "http://www.google.com/", 
  "http://lite.cnn.io/en/"
};

//===========================================================================
// PROCESSING DEFAULT FUNCTIONS:

void settings() {
  size(400, 600);
}

void setup() {

  textAlign(CENTER, CENTER);
  rectMode(CENTER);

  fill(255);
  strokeWeight(2); 

  for (String url : urls) {
    getRequest(url);
    getData(url);
    delay(2000); //NOT really needed but always be a good citizen
  }
  exit();
}

void draw(){}

//===========================================================================
// OTHER FUNCTIONS:

void getRequest(String url) {
  GetRequest get = new GetRequest(url); 
  get.send();
  String ret=get.getContent();
  println("====================GET /===========================");
  println("URL: ", url, "returned", ret.length(), "bytes (?)");
  println("Response Content:", ret.substring(0, OUTPUT_LEN), "...");
}

void getData(String url) {
  String[] str = loadStrings(url);  
  String ret=join(str, '\n');
  println("====================LOADSTRING===========================");
  println("URL: ", url, "returned", ret.length(), "bytes (?)");
  println("Response Content:", ret.substring(0, OUTPUT_LEN), "...");
}

```

---

<div class="post-metadata">

### Author: ![biran4454](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@biran4454](https://discourse.processing.org/u/biran4454)
#### Post date: [January 20, 2020, 7:36pm UTC](https://discourse.processing.org/t/processing-network-http-request-help/17069/4 "2020-01-20T19:36:22Z")

</div>

OK, thanks!! I’ll try that.
