本文整理汇总了Java中com.mashape.unirest.request.HttpRequestWithBody.queryString方法的典型用法代码示例。如果您正苦于以下问题:Java HttpRequestWithBody.queryString方法的具体用法?Java HttpRequestWithBody.queryString怎么用?Java HttpRequestWithBody.queryString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mashape.unirest.request.HttpRequestWithBody
的用法示例。
在下文中一共展示了HttpRequestWithBody.queryString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: post
import com.mashape.unirest.request.HttpRequestWithBody; //导入方法依赖的package包/类
/**
* @param cmd
* REST post type
* @param body
* REST Payload
* @param params
* to fill request with
* @param objs
* objects to replace in url
* @return Request with prepared parameters values
* @throws Exception
*/
public BaseRequest post(HbPost cmd, Object body, Params params,
String... objs)
throws Exception {
if (body == null) {
return post(cmd, params, objs);
} else {
HttpRequestWithBody postReq = post(apiLink + cmd.getCmd(objs));
if (params != null) {
postReq = postReq.queryString(params.getAll());
}
RequestBodyEntity entity;
if (body instanceof JsonNode) {
entity = postReq.body((JsonNode) body);
}
else if (body instanceof String) {
entity = postReq.body((String) body);
}
else {
entity = postReq.body(body);
}
return entity;
}
}
示例2: put
import com.mashape.unirest.request.HttpRequestWithBody; //导入方法依赖的package包/类
/**
* Makes PUT RESful API method based on {@link HbPost}
*
* @param cmd
* API command of type {@link HbPut}
* @param params
* REST parameters
* @param objs
* objects to replace in url
* @return {@link RequestBodyEntity}
* @throws Exception
*/
public BaseRequest put(HbPut cmd, Object body, Params params,
String... objs)
throws Exception {
HttpRequestWithBody putReq = put(apiLink + cmd.getCmd(objs));
putReq = putReq.queryString(params.getAll());
if (body != null) {
RequestBodyEntity entity;
if (body instanceof JsonNode) {
entity = putReq.body((JsonNode) body);
} else {
ObjectMapper om = new ObjectMapper();
String bodyS = om.writeValueAsString(body);
entity = putReq.body(bodyS);
}
return entity;
}
return put(cmd, params, objs);
}
示例3: save
import com.mashape.unirest.request.HttpRequestWithBody; //导入方法依赖的package包/类
@Override public <T extends Event<?>> void save(T event) throws Exception {
Map<String, String> data = null;
if (event instanceof ChangeEvent) {
ChangeEvent e = (ChangeEvent) event;
data = handle(e);
if (data != null) {
String uri = this.props.get("uri") + "/metrics";
HttpRequestWithBody request = Unirest.post(uri);
request.queryString("metric", e.variable());
request.queryString("value", data.get("value"));
data.remove("value");
for (String tag : data.keySet()) {
request.queryString("label[" + tag + "]", data.get(tag));
}
HttpResponse<String> response = request.asString();
if (Boolean.valueOf(this.props.get("output_responses"))) {
System.out.println(response.getStatusText() + "\t"
+ response.getBody());
}
}
}
}
示例4: addUploadedFilesToRepo
import com.mashape.unirest.request.HttpRequestWithBody; //导入方法依赖的package包/类
public void addUploadedFilesToRepo(String reponame, String uploaddir) throws AptlyRestException
{
// add to the repo
try {
HttpRequestWithBody req = Unirest.post(mSite.getUrl() +
"/api/repos/"+ reponame +"/file/" + uploaddir);
req.queryString("forceReplace", "1");
JSONObject res = sendRequest(req);
mLogger.printf("Uploaded packages added to repo, response: %s\n", res.toString());
}
catch (AptlyRestException ex) {
mLogger.printf("Failed to add uploaded packages to repo: %s\n", ex.toString());
throw ex;
}
}