Trying to read from a URL(in Java) produces gibberish on certain occaisions

后端 未结 4 801
清歌不尽
清歌不尽 2021-01-23 07:43

I\'m trying to read from a URL, and then print the result.

BufferedReader in = new BufferedReader(
     new InputStreamReader(new URL(\"http://somesite.com/\").o         


        
4条回答
  •  清酒与你
    2021-01-23 07:56

    Try using telnet to diagnose what's coming over the wire. It may not be textual data. For example, what happens when yo do this?

    telnet somesite.com 80
    GET / HTTP/1.0
    Host: somesite.com
    

    (two carriage returns required after last line)

    This should allow you to see the headers and content coming in and should give you a better clue as to what's going on.

提交回复
热议问题