Jave 模拟 http 请求
来源:互联网 发布:网络摄像机远程重启 编辑:程序博客网 时间:2024/05/21 08:57
在编写一个爬虫,当然必须要模拟http请求了!
于是又了下面的代码:
import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.io.OutputStreamWriter;import java.io.*;import java.net.URL;import java.net.URLConnection;public class httpTest {public static void testPost() throws IOException { URL url = new URL("https://foursquare.com/v/universal-studios-singapore/4b1ee9ebf964a5207e2124e3"); //set the url URLConnection connection = url.openConnection(); connection.setDoOutput(true); RandomAccessFile ra = new RandomAccessFile("E:\\html.html", "rw"); //set the out filename and path String sCurrentLine; String sTotalString; sCurrentLine = ""; sTotalString = ""; InputStream l_urlStream; l_urlStream = connection.getInputStream(); BufferedReader l_reader = new BufferedReader(new InputStreamReader( l_urlStream)); while ((sCurrentLine = l_reader.readLine()) != null) { sTotalString += sCurrentLine + "\r\n"; //sTotalString is the out put stream. } System.out.println(sTotalString); ra.writeBytes(sTotalString); ra.close(); } public static void main(String[] args) throws IOException { testPost(); } }
最终的接受到的html文件在E盘的html.html文件里面。
大家有没有什么好的关于java网络编程的书
比较系统的那种。谢谢!
- Jave 模拟 http 请求
- HttpWebRequest 模拟Http请求
- telnet模拟Http请求
- http请求模拟
- telnet模拟HTTP请求
- 模拟http 请求
- PHP模拟http请求
- HTTP 模拟post请求
- 模拟发送http请求
- socket模拟http请求
- 模拟HTTP请求
- c#模拟http请求
- C# 模拟 Http 请求
- java模拟http请求
- java模拟HTTP请求
- linux 模拟http请求
- php模拟http请求
- PHP模拟HTTP请求
- struts+spring的开发步骤
- Cannot find or open the PDB file
- A configuration error occurred during startup. Please verify the preference field with the prompt:
- 基于STM32的USB枚举过程学习笔记(二)
- GCD实战一:使用串行队列实现简单的预加载
- Jave 模拟 http 请求
- GCD实战2:资源竞争
- Timer和spring的Quartz两种定时器的区别。
- Linux进程及进程通讯
- 如何让wpf 中的textbox只能输入整型或浮点型
- 暮色中勤奋依旧—成都传智播客自习记
- PopupWindow
- hadoop二次排序一
- shell读取文件 随机读取