本文整理了Java中jodd.http.HttpRequest.header()
方法的一些代码示例,展示了HttpRequest.header()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpRequest.header()
方法的具体详情如下:
包路径:jodd.http.HttpRequest
类名称:HttpRequest
方法名:header
暂无
代码示例来源:origin: oblac/jodd
@Test
void testDefaultParameters() {
HttpBrowser httpBrowser = new HttpBrowser();
httpBrowser.setDefaultHeader("aaa", "123");
HttpRequest request = HttpRequest.get("foo.com");
request.header("bbb", "987");
httpBrowser.addDefaultHeaders(request);
assertEquals(3, request.headerNames().size());
assertEquals("123", request.header("aaa"));
assertEquals("987", request.header("bbb"));
}
代码示例来源:origin: oblac/jodd
.header("key-tEST2", "value2");
assertTrue(request.toString(false).contains("Key-Test2: value2"), "Header key should have been modified");
assertEquals("value2", request.headers("KEY-TEST2").get(0));
assertEquals("value2", request.headers("key-test2").get(0));
request.header("key-test2", "value3");
assertTrue(request.toString(false).contains("Key-Test2: value2, value3"), "Header key should have been modified");
assertEquals(2, request.headers("KEY-TEST2").size());
.header("KEY-TEST1", "VALUE1");
assertEquals("VALUE1", request.headers("key-test1").get(0));
request.header("key-test1", "value4");
assertTrue(request.toString(false).contains("key-test1: VALUE1, value4"), "Header key should not have been modified");
assertEquals(2, request.headers("KEY-TEST1").size());
代码示例来源:origin: oblac/jodd
if (header(HEADER_HOST) == null) {
setHostHeader();
if (header("User-Agent") == null) {
header("User-Agent", Defaults.userAgent);
代码示例来源:origin: oblac/jodd
@Test
void testInOutForm() {
HttpRequest request = HttpRequest.get("http://jodd.org/?id=173");
request.header("User-Agent", "Scaly");
request.form("one", "funny");
byte[] bytes = request.toByteArray();
// read
HttpRequest request2 = HttpRequest.readFrom(new ByteArrayInputStream(bytes));
assertEquals(request.method(), request2.method());
assertEquals(request.path(), request2.path());
assertEquals(request.queryString(), request2.queryString());
assertEquals(request.header("User-Agent"), request2.header("User-Agent"));
assertEquals(request.header("Content-Type"), request2.header("content-type"));
assertEquals(request.header("Content-Length"), request2.header("content-length"));
HttpMultiMap<?> params1 = request.form();
HttpMultiMap<?> params2 = request2.form();
assertEquals(params1.size(), params2.size());
assertEquals(params2.get("one"), params2.get("one"));
}
代码示例来源:origin: oblac/jodd
@Test
void testDefaultParametersOverwrite() {
HttpBrowser httpBrowser = new HttpBrowser();
httpBrowser.setDefaultHeader("aaa", "123");
HttpRequest request = HttpRequest.get("foo.com");
request.header("aaa", "987");
httpBrowser.addDefaultHeaders(request);
assertEquals(2, request.headerNames().size());
assertEquals("987", request.header("aaa"));
}
}
代码示例来源:origin: oblac/jodd
@Test
void testFileUpload() throws IOException {
HttpRequest request = HttpRequest.get("http://jodd.org/?id=173");
request.header("User-Agent", "Scaly").form("one", "funny");
File tempFile = FileUtil.createTempFile();
tempFile.deleteOnExit();
FileUtil.writeString(tempFile, "qwerty");
request.form("two", tempFile);
byte[] bytes = request.toByteArray();
// read
HttpRequest request2 = HttpRequest.readFrom(new ByteArrayInputStream(bytes));
HttpMultiMap<?> httpParams2 = request2.form();
assertEquals(request.method(), request2.method());
assertEquals(request.path(), request2.path());
assertEquals(request.queryString(), request2.queryString());
assertEquals(request.header("User-Agent"), request2.header("User-Agent"));
assertEquals(request.header("Content-Type"), request2.header("content-type"));
assertEquals(request.header("Content-Length"), request2.header("content-length"));
HttpMultiMap<?> params1 = request.form();
HttpMultiMap<?> params2 = request2.form();
assertEquals(params1.size(), params2.size());
assertEquals(params2.get("one"), params2.get("one"));
FileUpload fu = (FileUpload) httpParams2.get("two");
assertEquals(6, fu.getSize());
String str = new String(fu.getFileContent());
assertEquals("qwerty", str);
tempFile.delete();
}
代码示例来源:origin: oblac/jodd
assertEquals("Close", request.header("Connection"));
request.connectionKeepAlive(true);
assertTrue(request.isConnectionPersistent());
代码示例来源:origin: com.gitee.morilys.jsmile/jsmile-kit
/**
* http get请求
* @param url 请求地址
* @param param 请求参数
* @return
*/
public static String post(String url, Map<String,Object> param,Map<String,String> headers){
String result=null;
try {
HttpRequest httpRequest = HttpRequest.post(url);
if(null!=param){
httpRequest.form(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;
}
代码示例来源: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.gitee.morilys.jsmile/jsmile-kit
/**
* http post请求(body带参)
* @param url 请求地址
* @param param 请求参数
* @return
*/
public static String body(String url, Map<String,Object> param,Map<String,String> headers){
String result=null;
try {
HttpRequest httpRequest = HttpRequest.post(url).contentTypeJson();
if(null!=param){
httpRequest.body(JSON.toJSONString(param));
}else{
httpRequest.body("{}");
}
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;
}
代码示例来源:origin: org.jodd/jodd-http
if (header(HEADER_HOST) == null) {
setHostHeader();
if (header("User-Agent") == null) {
header("User-Agent", Defaults.userAgent);
代码示例来源:origin: com.liferay.launchpad/api-transport-jodd
httpRequest.header("Cookie",
new jodd.http.Cookie(cookie.encode()).toString());
httpRequest.header(
entry.getKey(), ValuesUtil.toString(entry.getValue()));
代码示例来源:origin: com.liferay.launchpad/api-client
header -> httpRequest.header(header.getKey(), header.getValue()));
内容来源于网络,如有侵权,请联系作者删除!