本文整理了Java中jodd.http.HttpRequest.query()
方法的一些代码示例,展示了HttpRequest.query()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpRequest.query()
方法的具体详情如下:
包路径:jodd.http.HttpRequest
类名称:HttpRequest
方法名:query
[英]Returns backend map of query parameters.
[中]返回查询参数的后端映射。
代码示例来源:origin: oblac/jodd
/**
* Adds many query parameters at once. Although it accepts objects,
* each value will be converted to string.
*/
public HttpRequest query(final String name1, final Object value1, final Object... parameters) {
query(name1, value1 == null ? null : value1.toString());
for (int i = 0; i < parameters.length; i += 2) {
String name = parameters[i].toString();
String value = parameters[i + 1].toString();
query.add(name, value);
}
return this;
}
代码示例来源:origin: oblac/jodd
private void testQueryParams(int i) throws IOException {
String encoding = i == 1 ? "UTF-8" : "CP1251";
HttpRequest request = HttpRequest.get("http://localhost:8173/echo2");
request.queryEncoding(encoding);
String value1 = "value";
String value2 = "валуе";
request.query("one", value1);
request.query("two", value2);
request.query("enc", encoding);
HttpResponse httpResponse = request.send();
assertTrue(Data.ref.get);
assertFalse(Data.ref.post);
assertEquals(3, Data.ref.params.size());
assertEquals(value1, Data.ref.params.get("one"));
assertEquals(value2, Data.ref.params.get("two"));
}
代码示例来源:origin: oblac/jodd
assertNotNull(httpRequest.query());
assertEquals(0, httpRequest.query().size());
HttpMultiMap<String> params = httpRequest.query();
assertEquals(1, params.size());
assertEquals("two", params.get("one"));
params = httpRequest.query();
assertEquals(1, params.size());
assertNull(params.get("one"));
params = httpRequest.query();
assertEquals(1, params.size());
assertEquals("", params.get("one"));
params = httpRequest.query();
assertEquals(2, params.size());
assertEquals("aaa", params.get("one"));
params = httpRequest.query();
assertEquals(2, params.size());
assertEquals("", params.get("one"));
httpRequest.queryString("one=Супер");
assertEquals("one=%D0%A1%D1%83%D0%BF%D0%B5%D1%80", httpRequest.queryString());
params = httpRequest.query();
assertEquals(1, params.size());
assertEquals("Супер", params.get("one"));
代码示例来源:origin: oblac/jodd
@Test
void test394() {
HttpRequest request = HttpRequest.get("https://jodd.org/random link");
assertEquals("GET", request.method());
assertEquals("https://jodd.org/random link", request.url());
request = HttpRequest.get("https://jodd.org/random link?q=1");
assertEquals("1", request.query().get("q"));
String badUrl = "httpsjodd.org/random link?q=1:// GET";
try {
HttpRequest.get(badUrl).send();
fail("error");
}
catch (HttpException he) {
assertTrue(he.getMessage().contains(badUrl));
}
}
代码示例来源:origin: oblac/jodd
assertEquals(173, httpRequest.port());
assertEquals("/index.html", httpRequest.path());
assertEquals("true", httpRequest.query().get("light"));
assertEquals(173, httpRequest.port());
assertEquals("/index.html", httpRequest.path());
assertEquals("true", httpRequest.query().get("light"));
assertEquals(173, httpRequest.port());
assertEquals("/index.html", httpRequest.path());
assertEquals("true", httpRequest.query().get("light"));
assertEquals(80, httpRequest.port());
assertEquals("/index.html", httpRequest.path());
assertEquals("true", httpRequest.query().get("light"));
assertEquals(80, httpRequest.port());
assertEquals("/index.html", httpRequest.path());
assertEquals("true", httpRequest.query().get("light"));
代码示例来源:origin: org.jodd/jodd-http
/**
* Adds many query parameters at once. Although it accepts objects,
* each value will be converted to string.
*/
public HttpRequest query(final String name1, final Object value1, final Object... parameters) {
query(name1, value1 == null ? null : value1.toString());
for (int i = 0; i < parameters.length; i += 2) {
String name = parameters[i].toString();
String value = parameters[i + 1].toString();
query.add(name, value);
}
return this;
}
代码示例来源:origin: com.gitee.morilys.jsmile/jsmile-kit
/**
* http get请求
* @param url 请求地址
* @param param 请求参数
* @return
*/
public static String get(String url, Map<String,String> param,Map<String,String> headers){
String result=null;
try {
HttpRequest httpRequest = HttpRequest.get(url);
if(null!=param){
httpRequest.query(param);
}
if(headers!=null&&!headers.isEmpty()){
httpRequest.header(headers);
}
HttpResponse response = httpRequest.send().charset(HttpConstant.Charsets.DEFAULT_CHARSET);
result = response.bodyText();
}catch (Exception e){
logger.error("HTTP请求地址【" + url + "】发生异常:" + ExceptionUtils.getRootCause(e));
}
return result;
}
public static String get(String url, Map<String,String> param){
代码示例来源:origin: com.github.binarywang/weixin-java-mp
@Override
public InputStream execute(String uri, String materialId) throws WxErrorException, IOException {
HttpRequest request = HttpRequest.post(uri);
if (requestHttp.getRequestHttpProxy() != null) {
requestHttp.getRequestHttpClient().useProxy(requestHttp.getRequestHttpProxy());
}
request.withConnectionProvider(requestHttp.getRequestHttpClient());
request.query("media_id", materialId);
HttpResponse response = request.send();
response.charset(StringPool.UTF_8);
try (InputStream inputStream = new ByteArrayInputStream(response.bodyBytes())) {
// 下载媒体文件出错
byte[] responseContent = IOUtils.toByteArray(inputStream);
String responseContentString = new String(responseContent, StandardCharsets.UTF_8);
if (responseContentString.length() < 100) {
try {
WxError wxError = WxGsonBuilder.create().fromJson(responseContentString, WxError.class);
if (wxError.getErrorCode() != 0) {
throw new WxErrorException(wxError);
}
} catch (com.google.gson.JsonSyntaxException ex) {
return new ByteArrayInputStream(responseContent);
}
}
return new ByteArrayInputStream(responseContent);
}
}
}
代码示例来源:origin: binarywang/WxJava
@Override
public InputStream execute(String uri, String materialId) throws WxErrorException, IOException {
HttpRequest request = HttpRequest.post(uri);
if (requestHttp.getRequestHttpProxy() != null) {
requestHttp.getRequestHttpClient().useProxy(requestHttp.getRequestHttpProxy());
}
request.withConnectionProvider(requestHttp.getRequestHttpClient());
request.query("media_id", materialId);
HttpResponse response = request.send();
response.charset(StringPool.UTF_8);
try (InputStream inputStream = new ByteArrayInputStream(response.bodyBytes())) {
// 下载媒体文件出错
byte[] responseContent = IOUtils.toByteArray(inputStream);
String responseContentString = new String(responseContent, StandardCharsets.UTF_8);
if (responseContentString.length() < 100) {
try {
WxError wxError = WxGsonBuilder.create().fromJson(responseContentString, WxError.class);
if (wxError.getErrorCode() != 0) {
throw new WxErrorException(wxError);
}
} catch (com.google.gson.JsonSyntaxException ex) {
return new ByteArrayInputStream(responseContent);
}
}
return new ByteArrayInputStream(responseContent);
}
}
}
代码示例来源:origin: com.liferay.launchpad/api-client
param -> httpRequest.query(param.getKey(), param.getValue()));
代码示例来源:origin: com.liferay.launchpad/api-transport-jodd
httpRequest.query(
entry.getKey(), ValuesUtil.toString(entry.getValue()));
代码示例来源:origin: binarywang/WxJava
@Override
public Boolean execute(String uri, String materialId) throws WxErrorException, IOException {
HttpRequest request = HttpRequest.post(uri);
if (requestHttp.getRequestHttpProxy() != null) {
requestHttp.getRequestHttpClient().useProxy(requestHttp.getRequestHttpProxy());
}
request.withConnectionProvider(requestHttp.getRequestHttpClient());
request.query("media_id", materialId);
HttpResponse response = request.send();
response.charset(StringPool.UTF_8);
String responseContent = response.bodyText();
WxError error = WxError.fromJson(responseContent, WxType.MP);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
} else {
return true;
}
}
}
代码示例来源:origin: com.github.binarywang/weixin-java-mp
@Override
public Boolean execute(String uri, String materialId) throws WxErrorException, IOException {
HttpRequest request = HttpRequest.post(uri);
if (requestHttp.getRequestHttpProxy() != null) {
requestHttp.getRequestHttpClient().useProxy(requestHttp.getRequestHttpProxy());
}
request.withConnectionProvider(requestHttp.getRequestHttpClient());
request.query("media_id", materialId);
HttpResponse response = request.send();
response.charset(StringPool.UTF_8);
String responseContent = response.bodyText();
WxError error = WxError.fromJson(responseContent, WxType.MP);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
} else {
return true;
}
}
}
代码示例来源:origin: com.github.binarywang/weixin-java-mp
@Override
public WxMpMaterialVideoInfoResult execute(String uri, String materialId) throws WxErrorException, IOException {
HttpRequest request = HttpRequest.post(uri);
if (requestHttp.getRequestHttpProxy() != null) {
requestHttp.getRequestHttpClient().useProxy(requestHttp.getRequestHttpProxy());
}
request.withConnectionProvider(requestHttp.getRequestHttpClient());
request.query("media_id", materialId);
HttpResponse response = request.send();
response.charset(StringPool.UTF_8);
String responseContent = response.bodyText();
WxError error = WxError.fromJson(responseContent, WxType.MP);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
} else {
return WxMpMaterialVideoInfoResult.fromJson(responseContent);
}
}
}
代码示例来源:origin: binarywang/WxJava
@Override
public WxMpMaterialVideoInfoResult execute(String uri, String materialId) throws WxErrorException, IOException {
HttpRequest request = HttpRequest.post(uri);
if (requestHttp.getRequestHttpProxy() != null) {
requestHttp.getRequestHttpClient().useProxy(requestHttp.getRequestHttpProxy());
}
request.withConnectionProvider(requestHttp.getRequestHttpClient());
request.query("media_id", materialId);
HttpResponse response = request.send();
response.charset(StringPool.UTF_8);
String responseContent = response.bodyText();
WxError error = WxError.fromJson(responseContent, WxType.MP);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
} else {
return WxMpMaterialVideoInfoResult.fromJson(responseContent);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!