资源简介
http客户端java程序,代码质量高,经过测试。
代码片段和文件信息
package com.tcl.dhome.server.protocol.http;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.Socket;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.Enumeration;
import java.util.Properties;
public class HttpClient{
protected Socket socket;
protected BufferedOutputStream sender;
protected BufferedInputStream receiver;
protected ByteArrayInputStream byteStream;
protected URL targetUrl;
private int responseCode = -1;
private String responseMessage = ““;
private String serverVersion = ““;
private int responseLength =0;
private Properties headerProp = new Properties();
public HttpClient(){}
public HttpClient(String url){
GET(url);
}
/* GET方法根据URL,会请求文件、数据库查询结果、程序运行结果等多种内容 */
public void GET(String url){
try{
checkHTTP(url);
openServer(targetUrl.getHost()targetUrl.getPort());
String cmd = “GET “ + getURLFormat(targetUrl) + “ HTTP/1.0\r\n“
+ getbaseHeads() + “\r\n“;
sendMessage(cmd);
receiveMessage();
}
catch(ProtocolException p){
p.printStackTrace();
return;
}
catch(UnknownHostException e){
e.printStackTrace();
return;
}
catch(IOException i){
i.printStackTrace();
return;
}
}
/*
* HEAD方法只请求URL的元信息,不包括URL本身。若怀疑本机和服务器上的
* 文件相同,用这个方法检查最快捷有效。
*/
public void HEAD(String url){
try{
checkHTTP(url);
openServer(targetUrl.getHost()targetUrl.getPort());
String cmd = “HEAD “ + getURLFormat(targetUrl) + “ HTTP/1.0\r\n“
+ getbaseHeads() + “\r\n“;
sendMessage(cmd);
receiveMessage();
}
catch(ProtocolException p){
p.printStackTrace();
return;
}
catch(UnknownHostException e){
e.printStackTrace();
return;
}
catch(IOException i){
i.printStackTrace();
return;
}
}
/*
* POST方法是向服务器传送数据,以便服务器做出相应的处理。例如网页上常用的
* 提交表格。
*/
public void POST(String url String content){
try{
checkHTTP(url);
openServer(targetUrl.getHost()targetUrl.getPort());
String cmd = “POST “ + getURLFormat(targetUrl) + “ HTTP/1.0\r\n“
+ getbaseHea
相关资源
- HttpClient jar包
- httpcore-4.1.2.jar
- Android 仿新浪微博客户端APP源码.rar
- cas-client-autoconfig-support Apereo Java客户端
- Java 解析http请求处理结果
- httpclient-4.3.4.jar
- httpclient-4.3.6.jar
- Elasticsearch5.5.1 JAVA客户端RestClient
- 服务器端和客户端五子棋
- org.apache.http.entity.mime
- Android使用OkHttp访问自签名证书的接口
- java访问https网址文件(含证书)
- HttpServletRequest源码 HttpServletResponse源码
- okHttp-3.11.0
- 可联机的围棋对弈小程序
- java网络计算器
- ApacheJMeter_http.jar60720
- OKHttp3 所有Jarb包
- ftp安装 Java实现客户端
- Android购物网站源代码(客户端+服务器
- Java实现的一个FTP客户端
- http接口需要的jar包
- jstl.jar和standard.jar 报错Can not find \“
- 基于JavaSocket多客户端并发通信聊天程
- java访问https网址文件
- java实现聊天室功能包含全部代码,有
- httpclient get/post请求工具类map参数封装
- HttpClient4.5 实现https忽略SSL证书验证
- JAVA发送HTTP请求操作类
- webmagic修复HTTPS下无法抓取只支持TLS
评论
共有 条评论