How can I send an HTTP Response using only standard network libraries?

前端 未结 3 541
旧时难觅i
旧时难觅i 2021-01-26 15:17

I\'m working on my first homework project in a web programming class, which is to write a simple web server in Java. I\'m at the point where I have data being transmitted back a

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-26 15:52

    Based on your reported symptoms, I think the real problem is that you are not actually talking to your server at all! The evidence is that 1) you cannot get a 404 response, and 2) a 200 response does not have the content length and type. Neither of these should be possible ... if you are really talking to the code listed above.

    Maybe:

    • you are talking to an older version of your code; i.e. something is going wrong in your build / deploy cycle,
    • you are (mistakenly) trying to deploy / run your code in a web container (Jetty, Tomcat, etc), or
    • your client code / browser is actually talking to a different server due to proxying, an incorrect URL, or something like that.

    I suggest that you add some trace printing / logging at appropriate points of your code to confirm that it is actually being invoked.

提交回复
热议问题