• 大小: 0.01M
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2020-12-27
  • 标签: 网络  

资源简介

将String urlAddress= 这个网址改成 任意公网网址即可进行测试,比如可以改成 http://www.haolizi.net

资源截图

代码片段和文件信息

package org.lanqiao;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class URLGet {

public static void main(String[] args) {
String urlAddress=“http://localhost:8080/TestWeb/login.jsp“;
try {
URL url=new URL(urlAddress);
HttpURLConnection hc=(HttpURLConnection)url.openConnection();

InputStream is=hc.getInputStream();
BufferedReader br=new BufferedReader(
new InputStreamReader(is));
String line=null;
while((line=br.readLine())!=null){
System.out.println(line);
}


// 设置是否向httpUrlConnection输出,因为这个是post请求,参数要放在 
// http正文内,因此需要设为true 默认情况下是fa

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

    I.A....       301  2015-08-31 15:32  HttpURLConnectionTest\.classpath

    I.A....       397  2015-08-31 15:32  HttpURLConnectionTest\.project

    I.A....       598  2015-08-31 15:32  HttpURLConnectionTest\.settings\org.eclipse.jdt.core.prefs

    I.A....         3  2015-08-31 15:32  HttpURLConnectionTest\.svn\entries

    I.A....         3  2015-08-31 15:32  HttpURLConnectionTest\.svn\format

    I.A....       397  2015-08-31 15:32  HttpURLConnectionTest\.svn\pristine\0c\0cf3c81f22782327c18a3d4884c43da461506789.svn-base

    I.A....      1694  2015-08-31 15:32  HttpURLConnectionTest\.svn\pristine\32\320c2e638d033bd7c2135238b4e11c415a704774.svn-base

    I.A....       598  2015-08-31 15:32  HttpURLConnectionTest\.svn\pristine\af\af7fe7fb2d26f84718d29a6c151fe0b5395a6b9b.svn-base

    I.A....       301  2015-08-31 15:32  HttpURLConnectionTest\.svn\pristine\b8\b871a406b31b850f5e1d7251f9c8e368fe6972be.svn-base

    I.A....     38912  2015-08-31 15:32  HttpURLConnectionTest\.svn\wc.db

     文件       1966  2015-09-03 15:49  HttpURLConnectionTest\bin\org\lanqiao\URLGet.class

    I.A....      1694  2015-08-31 15:32  HttpURLConnectionTest\src\org\lanqiao\URLGet.java

    I..D...         0  2015-08-31 15:32  HttpURLConnectionTest\.svn\pristine\0c

    I..D...         0  2015-08-31 15:32  HttpURLConnectionTest\.svn\pristine\32

    I..D...         0  2015-08-31 15:32  HttpURLConnectionTest\.svn\pristine\af

    I..D...         0  2015-08-31 15:32  HttpURLConnectionTest\.svn\pristine\b8

     目录          0  2015-09-03 15:49  HttpURLConnectionTest\bin\org\lanqiao

     目录          0  2015-08-31 15:32  HttpURLConnectionTest\src\org\lanqiao

    I..D...         0  2015-08-31 15:32  HttpURLConnectionTest\.svn\pristine

    I..D...         0  2015-08-31 15:32  HttpURLConnectionTest\.svn\tmp

     目录          0  2015-09-03 15:49  HttpURLConnectionTest\bin\org

     目录          0  2015-08-31 15:32  HttpURLConnectionTest\src\org

     目录          0  2015-08-31 15:32  HttpURLConnectionTest\.settings

    I..D.H.         0  2015-08-31 15:32  HttpURLConnectionTest\.svn

     目录          0  2015-09-03 15:49  HttpURLConnectionTest\bin

     目录          0  2015-08-31 15:32  HttpURLConnectionTest\src

     目录          0  2015-08-31 15:32  HttpURLConnectionTest

----------- ---------  ---------- -----  ----

                46864                    27



............此处省略0个文件信息

评论

共有 条评论