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

Ubuntu Focal 20.04 update with kept back files

1  Asked on December 22, 2020 by topper


Is Huion Kamvas Pro 13 supported?

2  Asked on December 21, 2020 by gianluca-micchi


How do I run memtest86+?

2  Asked on December 21, 2020 by christopher-kyle-horton


IOMMU GPU Passthrough

0  Asked on December 20, 2020 by sparta


Install and run Zoom Client inside a sandbox

1  Asked on December 20, 2020 by pablo-bianchi


Primary button goes back to default on external mouse

2  Asked on December 19, 2020 by flipjacob


Could not find driver: com.mysql.jdbc.Driver

0  Asked on December 19, 2020 by nicholas-saunders


How to exclude directory with mandb?

0  Asked on December 19, 2020 by goose


Intel Display Audio Not Detected

0  Asked on December 18, 2020 by jonathan-heitz


How do I manually install a man page file?

4  Asked on December 17, 2020 by flimm


Do I need libsnapd-glib1 without snapd?

1  Asked on December 17, 2020 by buntubunny


Anyway to manage snap security in Puppet or Ansible?

0  Asked on December 17, 2020 by sam-klein


Dual Boot on Dell G5 SE w/ AMD Ryzen 7 4800 – Display Issues

1  Asked on December 17, 2020 by jeff-wilkerson


Ask a Question

Get help from others!

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