Can't issue an HTTP request to my Apache2 local server within my IDE

Ask Ubuntu Asked by Delio on November 2, 2020

I’ve just installed Apache2 on my Ubuntu machine and I’ve created a simple HTML (Hello World message) page within the dedicated directory for such content:


I’m able to see the "Hello Word" message on my browser (Firefox). I used the common URL to perform this kind of operation:

It works well!

but when I’m trying to do the same request with some Java code it only return me a 400 error:

HTTP/1.1 400 Bad Request
Date: Wed, 21 Oct 2020 15:45:21 GMT
Server: Apache/2.4.41 (Ubuntu)
Content-Length: 301
Connection: close
Content-Type: text/html; charset=iso-8859-1

My Java code looks like this:

public static void main(String[] args) throws UnknownHostException, IOException {
          // The host and port to be connected.
      String host = "";
      int port = 80;
      // Create a TCP socket and connect to the host:port.
      Socket socket = new Socket(host, port);
      // Create the input and output streams for the network socket.
      BufferedReader in
         = new BufferedReader(
              new InputStreamReader(socket.getInputStream()));
      PrintWriter out
         = new PrintWriter(socket.getOutputStream(), true);
      // Send request to the HTTP server.
      out.println("GET /example/index.html HTTP/1.1");
      out.println();   // blank line separating header & body
      // Read the response and display on console.
      String line;
      // readLine() returns null if server close the network socket.
      while((line = in.readLine()) != null) {
      // Close the I/O streams.

Can someone help me?

Add your own answers!

Related Questions

Teamviewer 11 won’t work on Ubuntu 20 Login Screen

1  Asked on November 23, 2021 by nikola-tepavac


Network interfaces not enabled at boot

1  Asked on November 23, 2021 by alexander-trauzzi


Clear swap on every shutdown

0  Asked on November 23, 2021 by corrupt_disk1


How to setup my Scarlett 2i2?

1  Asked on November 21, 2021 by bebel


GRUB not responding to keyboard

17  Asked on November 21, 2021 by brianw


Arrow Keys not working in GRUB

9  Asked on November 21, 2021 by user218937


Abort class-pclzip.php : Missing zlib extensions

2  Asked on November 21, 2021 by zkvvoob


Unattended-Upgrade::Automatic-Reboot default value

3  Asked on November 21, 2021 by stringer


Usb wifi dropped out / rtl8192eu-linux-driver on Ubuntu 16.04

1  Asked on November 21, 2021 by steve-mcgarry


Install mercusys wifi adapter in Ubuntu 20.04

1  Asked on November 21, 2021 by frostfox


Has ‘Ubuntu Software’ been renamed to ‘Snap Store’?

5  Asked on November 21, 2021 by mekacher-anis


Ask a Question

Get help from others!

© 2022 All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP