public class NetUtils extends Object
Modifier and Type | Field and Description |
---|---|
static String |
HOST_KEY
主机
|
static String |
PATH_KEY
路径
|
static String |
PROTOCOL_KEY
协议
|
Modifier and Type | Method and Description |
---|---|
static boolean |
addCookie(javax.servlet.http.Cookie cookie,
javax.servlet.http.HttpServletResponse response)
添加Cookie
|
static boolean |
addCookie(javax.servlet.http.HttpServletResponse response,
String name,
String value)
添加Cookie
|
static boolean |
addCookie(javax.servlet.http.HttpServletResponse response,
String name,
String value,
int expiry,
String uri)
添加Cookie
|
static boolean |
clearCookie(javax.servlet.http.Cookie[] cookies,
javax.servlet.http.HttpServletResponse response)
清除所有Cookie
|
static boolean |
clearCookie(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
清除所有Cookie
|
static String |
delete(String url,
com.alibaba.fastjson.JSONObject body)
DELETE请求
|
static String |
delete(String url,
Map<String,String> body)
DELETE请求
|
static String |
delete(String url,
String body)
DELETE请求
|
static String |
evaluate(String xpath,
String html)
XPath解析HTML内容
|
static String |
get(String url,
com.alibaba.fastjson.JSONObject body)
GET请求
|
static String |
get(String url,
Map<String,String> body)
GET请求
|
static String |
get(String url,
String body)
GET请求
|
static String |
getComputerName()
获取计算机名
|
static javax.servlet.http.Cookie |
getCookie(String name,
javax.servlet.http.Cookie[] cookies)
通过名称获取Cookie
|
static javax.servlet.http.Cookie |
getCookie(String name,
javax.servlet.http.HttpServletRequest request)
通过名称获取Cookie
|
static String |
getDataOfUrl(String url)
获取URL中的数据
|
static String |
getDataOfUrl(URL url)
获取URL中的数据
|
static org.jsoup.nodes.Document |
getDocumentFromUrl(String url)
获取HTML文档
|
static String |
getHtmlFromUrl(String url)
获取网页内容
|
static InputStream |
getInputStreamOfConnection(HttpURLConnection connection)
获取HttpURLConnection的InputStream对象
|
static InputStream |
getInputStreamOfUrl(String url)
获取URL的InputStream对象
|
static InputStream |
getInputStreamOfUrl(URL url)
获取URL的InputStream对象
|
static String |
getLocalIp()
获取本地ip地址
|
static String |
getLocationByIp(String ip)
获取ip归属地
|
static String |
getMacAddress()
获取Mac地址
|
static com.alibaba.fastjson.JSONObject |
getPublicIpAndLocation()
获取公网IP和归属地
|
static String |
getSystemArch()
获取系统架构
|
static String |
getSystemName()
获取系统名称
|
static String |
getSystemVersion()
获取系统版本
|
static boolean |
isAjax(javax.servlet.http.HttpServletRequest request)
是否是 ajax请求
|
static Map<String,String> |
parseUrl(String url)
解析URL
|
static String |
post(String url,
com.alibaba.fastjson.JSONObject body)
POST请求
|
static String |
post(String url,
Map<String,String> body)
POST请求
|
static String |
post(String url,
String body)
POST请求
|
static String |
put(String url,
com.alibaba.fastjson.JSONObject body)
PUT请求
|
static String |
put(String url,
Map<String,String> body)
PUT请求
|
static String |
put(String url,
String body)
PUT请求
|
static boolean |
removeCookie(javax.servlet.http.Cookie cookie,
javax.servlet.http.HttpServletResponse response)
删除指定Cookie
|
static boolean |
removeCookie(String name,
javax.servlet.http.Cookie[] cookies,
javax.servlet.http.HttpServletResponse response)
删除指定Cookie
|
static boolean |
removeCookie(String name,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
删除指定Cookie
|
static String |
replaceLocalHost(String domain)
替换localhost为127.0.0.1
|
static cn.hutool.http.HttpResponse |
request(cn.hutool.http.HttpRequest request,
String body)
发出网络请求
|
static cn.hutool.http.HttpResponse |
request(cn.hutool.http.HttpRequest request,
String body,
String contentType)
发出网络请求
|
static String |
scriptFilter(String string)
脚本过滤
|
static <T> ResultObject<T> |
upload(byte[] bytes,
SimpleMultipartFile simpleMultipartFile,
MultipartFileService<T> multipartFileService)
上传文件,简化业务代码
|
static String |
urlToString(URL url)
将URL转换成String
|
static String |
whois(String domain)
whois查询
|
public static final String PROTOCOL_KEY
public static final String HOST_KEY
public static final String PATH_KEY
public static <T> ResultObject<T> upload(byte[] bytes, SimpleMultipartFile simpleMultipartFile, MultipartFileService<T> multipartFileService)
T
- 原型类bytes
- MultipartFile#getBytessimpleMultipartFile
- 请设置一下值:SimpleMultipartFile.setOriginalFilename(String)
, SimpleMultipartFile.setSize(Long)
, SimpleMultipartFile.setStoragePath(String)
multipartFileService
- 请至少实现 MultipartFileService
接口中的一个方法ResultObject
public static String delete(String url, String body)
url
- 请求的URLbody
- 内容正文public static String delete(String url, Map<String,String> body)
url
- 请求的URLbody
- 内容正文public static String delete(String url, com.alibaba.fastjson.JSONObject body)
url
- 请求的URLbody
- 内容正文public static String put(String url, String body)
url
- 请求的URLbody
- 内容正文public static String put(String url, Map<String,String> body)
url
- 请求的URLbody
- 内容正文public static String put(String url, com.alibaba.fastjson.JSONObject body)
url
- 请求的URLbody
- 内容正文public static String get(String url, String body)
url
- 请求的URLbody
- 内容正文public static String get(String url, Map<String,String> body)
url
- 请求的URLbody
- 内容正文public static String get(String url, com.alibaba.fastjson.JSONObject body)
url
- 请求的URLbody
- 内容正文public static String post(String url, String body)
url
- 请求的URLbody
- 内容正文public static String post(String url, Map<String,String> body)
url
- 请求的URLbody
- 内容正文public static String post(String url, com.alibaba.fastjson.JSONObject body)
url
- 请求的URLbody
- 内容正文public static cn.hutool.http.HttpResponse request(cn.hutool.http.HttpRequest request, String body)
request
- HttpRequest
body
- 请求正文HttpResponse
public static cn.hutool.http.HttpResponse request(cn.hutool.http.HttpRequest request, String body, String contentType)
request
- HttpRequest
body
- 请求正文contentType
- 内容类型HttpResponse
public static String replaceLocalHost(String domain)
domain
- 域名public static boolean isAjax(javax.servlet.http.HttpServletRequest request)
request
- HttpServletRequest
Boolean
public static Map<String,String> parseUrl(String url)
url
- urlMap
public static String scriptFilter(String string)
string
- String
public static boolean clearCookie(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
request
- HttpServletRequest
response
- HttpServletResponse
Boolean
public static boolean clearCookie(javax.servlet.http.Cookie[] cookies, javax.servlet.http.HttpServletResponse response)
cookies
- Cookie
response
- HttpServletResponse
Boolean
public static boolean removeCookie(String name, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
name
- Cookie名request
- HttpServletRequest
response
- HttpServletResponse
Boolean
public static boolean removeCookie(String name, javax.servlet.http.Cookie[] cookies, javax.servlet.http.HttpServletResponse response)
name
- Cookie名cookies
- Cookie
response
- HttpServletResponse
Boolean
public static boolean removeCookie(javax.servlet.http.Cookie cookie, javax.servlet.http.HttpServletResponse response)
cookie
- Cookie
response
- HttpServletResponse
Boolean
public static boolean addCookie(javax.servlet.http.Cookie cookie, javax.servlet.http.HttpServletResponse response)
cookie
- Cookie
response
- HttpServletResponse
Boolean
public static boolean addCookie(javax.servlet.http.HttpServletResponse response, String name, String value)
response
- HttpServletResponse
name
- Cookie名value
- Cookie值Boolean
public static boolean addCookie(javax.servlet.http.HttpServletResponse response, String name, String value, int expiry, String uri)
response
- HttpServletResponse
name
- Cookie名value
- Cookie值expiry
- 有效期uri
- 路径Boolean
public static javax.servlet.http.Cookie getCookie(String name, javax.servlet.http.HttpServletRequest request)
name
- Cookie名request
- HttpServletRequest
Cookie
public static javax.servlet.http.Cookie getCookie(String name, javax.servlet.http.Cookie[] cookies)
name
- Cookie名cookies
- cookie数组Cookie
public static String whois(String domain) throws IOException, XPathExpressionException, ParserConfigurationException
domain
- 域名IOException
- 异常XPathExpressionException
- 异常ParserConfigurationException
- 异常public static String getLocationByIp(String ip) throws IOException, XPathExpressionException, ParserConfigurationException
ip
- ip地址IOException
- 异常XPathExpressionException
- 异常ParserConfigurationException
- 异常public static String evaluate(String xpath, String html) throws XPathExpressionException, ParserConfigurationException
xpath
- xpath表达式html
- html内容XPathExpressionException
- 异常ParserConfigurationException
- 异常public static String getHtmlFromUrl(String url) throws IOException
url
- 链接String
IOException
- 异常public static org.jsoup.nodes.Document getDocumentFromUrl(String url) throws IOException
url
- 链接Document
IOException
- 异常public static String getComputerName()
public static String getSystemName()
public static String getSystemArch()
public static String getSystemVersion()
public static String getMacAddress() throws UnknownHostException, SocketException
UnknownHostException
- 异常SocketException
- 异常public static com.alibaba.fastjson.JSONObject getPublicIpAndLocation() throws IOException
IOException
- 异常public static String getLocalIp() throws UnknownHostException
UnknownHostException
- 异常public static String getDataOfUrl(String url) throws IOException
url
- 网络链接String
IOException
- 异常public static String getDataOfUrl(URL url) throws IOException
url
- 网络链接String
IOException
- 异常public static InputStream getInputStreamOfUrl(String url) throws IOException
url
- 网络链接InputStream
IOException
- 异常public static InputStream getInputStreamOfUrl(URL url) throws IOException
url
- 网络链接InputStream
IOException
- 异常public static InputStream getInputStreamOfConnection(HttpURLConnection connection) throws IOException
connection
- 链接对象InputStream
IOException
- 异常Copyright © 2018. All rights reserved.