我使用类似"http://www.example.com/a?s=12"的字符串创建URL对象。我在字符串serverResponse中读取了HTML响应。该字符串应具有页面的整个HTML,其中包含JavaScript和CSS。但是奇怪的是,响应中存在的所有URL中都缺少“ http:”一词,例如代替"http://example.com"我得到了"//asd.com"。有任何想法吗?

    URL obj = new URL(url);
    HttpURLConnection con = (HttpURLConnection) obj.openConnection();
    con.setRequestMethod("GET");

    BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
    String inputLine;
    StringBuffer serverResponse = new StringBuffer();

    while ((inputLine = in.readLine()) != null) {
        serverResponse.append(inputLine);
        System.out.println(inputLine);
    }
    in.close();

    System.out.println(serverResponse);

最佳答案

看到这里:Protocol-relative URLs

07-24 18:50