• Post Reply Bookmark Topic Watch Topic
  • New Topic

webserver, 400 response  RSS feed

 
Brenda Stevens
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am slightly stuck with creating a webserver i need to be able to check the resource name (from the first line of the client request) to see that it starts with a “/” and if not it will return a 400 response. I have an idea but not quite sure. heres what i have come up with so far:

If(! (firstLine.startsWith(“/”)
{
System.out.println(“400 Bad request”);
String reply= “HTTP/1.1 400 Bad Request\r\n” +
“Connection: close\r\n” +
“Content-Type: text/html\r\n" +
"\r\n" +
"<h1>Sorry, bad request</h1>\r\n";
OutputStream outs = conn.getOutputStream();
outs.write(reply.getBytes());


 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brenda Stevens wrote:...I have an idea but not quite sure...

What is it, exactly, that you're not sure about?
 
Brenda Stevens
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just wanted to make sure that that was the correct way it is suppose to be written and returns the correct message
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you test it?
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags when posting code. It will highlight your code, making it much easier to read. You can edit your post with the button.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!