public class IotHttpRequest extends AbstractHttpRequest
post 如不设置body内容,方法contentType默认是application/x-www-form-urlencoded,
| 限定符和类型 | 字段和说明 |
|---|---|
protected Map<String,Object> |
bodyParameters
请求体map对象
如bodyParameters不为空,会转为json,放入body中
|
protected Map<String,Object> |
form
支持常见的form表单类型
application/x-www-form-urlencoded
multipart/form-data
|
protected HttpRequest |
httpRequest
http 请求工具类
|
| 构造器和说明 |
|---|
IotHttpRequest(String url)
默认GET方法
|
IotHttpRequest(String url,
Method method)
构造器
|
IotHttpRequest(String url,
Method method,
boolean needAuth)
构造器
|
IotHttpRequest(String url,
Method method,
boolean needAuth,
Map<String,Object> form)
form表单构造器
|
IotHttpRequest(String url,
Method method,
boolean needAuth,
String body)
附带body构造器
|
IotHttpRequest(String url,
Method method,
Map<String,Object> form)
form表单构造器
|
IotHttpRequest(String url,
Method method,
String body)
body请求体构造器
|
| 限定符和类型 | 方法和说明 |
|---|---|
IotHttpRequest |
body(String body)
设置Body
|
String |
execute()
执行调用
|
HttpResponse |
executeResponse() |
IotHttpRequest |
form(Map<String,Object> formParam)
添加form表单参数
|
IotHttpRequest |
form(String name,
Object value)
添加form表单参数
|
IotHttpRequest |
get(String url)
GET构造器
|
String |
getBody() |
Map<String,Object> |
getBodyParameters() |
Map<String,Object> |
getForm() |
Map<String,String> |
getHeader() |
HttpRequest |
getHttpRequest() |
Method |
getMethod() |
String |
getUrl() |
IotHttpRequest |
header(String name,
String value)
请求头
|
boolean |
isNeedAuth() |
static void |
main(String[] args) |
IotHttpRequest |
post(String url)
POST构造器
|
void |
setBody(String body) |
void |
setForm(Map<String,Object> form) |
void |
setHeader(Map<String,String> header) |
void |
setHttpRequest(HttpRequest httpRequest) |
void |
setMethod(Method method) |
void |
setNeedAuth(boolean needAuth) |
void |
setUrl(String url) |
protected final Map<String,Object> bodyParameters
如bodyParameters不为空,会转为json,放入body中
protected HttpRequest httpRequest
public IotHttpRequest(String url, Method method) throws ClientException
url - 请求地址method - 方法类型ClientException - 客户端类型异常public IotHttpRequest(String url, Method method, boolean needAuth) throws ClientException
url - 请求地址method - 方法类型needAuth - 是否需要鉴权,默认trueClientException - 请求异常public IotHttpRequest(String url, Method method, boolean needAuth, String body) throws ClientException
url - 请求地址method - 方法类型needAuth - 是否需要鉴权,默认truebody - 请求体bodyClientException - 请求异常public IotHttpRequest(String url, Method method, boolean needAuth, Map<String,Object> form) throws ClientException
url - 请求地址method - 方法类型needAuth - 是否需要鉴权,默认trueform - map类型ClientException - 请求异常public IotHttpRequest(String url, Method method, String body) throws ClientException
url - 请求地址method - 方法类型body - 默认json字符串ClientException - 请求异常public IotHttpRequest(String url, Method method, Map<String,Object> form) throws ClientException
url - 请求地址method - 方法类型form - map类型ClientException - 请求异常public IotHttpRequest(String url) throws ClientException
url - 请求地址ClientException - 请求异常public static void main(String[] args)
public IotHttpRequest post(String url)
url - 请求地址public IotHttpRequest get(String url)
url - 请求地址public IotHttpRequest body(String body)
body - 请求体,默认json对象public IotHttpRequest header(String name, String value)
name - 请求头namevalue - 请求头valuepublic IotHttpRequest form(String name, Object value)
name - form键namevalue - form值valuepublic IotHttpRequest form(Map<String,Object> formParam)
formParam - mappublic String execute()
public HttpResponse executeResponse()
public HttpRequest getHttpRequest()
public void setHttpRequest(HttpRequest httpRequest)
public String getUrl()
public void setUrl(String url)
public Method getMethod()
public void setMethod(Method method)
public String getBody()
public void setBody(String body)
public boolean isNeedAuth()
public void setNeedAuth(boolean needAuth)
Copyright © 2023. All rights reserved.