jodd.http.HttpResponse.cookies()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(1.5k)|赞(0)|评价(0)|浏览(171)

本文整理了Java中jodd.http.HttpResponse.cookies()方法的一些代码示例,展示了HttpResponse.cookies()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.cookies()方法的具体详情如下:
包路径:jodd.http.HttpResponse
类名称:HttpResponse
方法名:cookies

HttpResponse.cookies介绍

[英]Returns list of valid cookies sent from server. If no cookie found, returns an empty array. Invalid cookies are ignored.
[中]返回从服务器发送的有效Cookie列表。如果未找到cookie,则返回空数组。无效的cookies将被忽略。

代码示例

代码示例来源:origin: oblac/jodd

/**
 * Reads cookies from response and adds to cookies list.
 */
protected void readCookies(final HttpResponse httpResponse) {
  Cookie[] newCookies = httpResponse.cookies();
  for (Cookie cookie : newCookies) {
    cookies.add(cookie.getName(), cookie);
  }
}

代码示例来源:origin: oblac/jodd

@Test
void testBrowser() {
  HttpBrowser httpBrowser = new HttpBrowser();
  httpBrowser.sendRequest(
    HttpRequest
      .get("localhost:8173/echo?id=17")
      .cookies(new Cookie("waffle", "jam"))
      .bodyText("hello"));
  HttpResponse httpResponse = httpBrowser.getHttpResponse();
  assertNotNull(httpResponse);
  assertEquals("hello", httpResponse.body());
  Cookie[] cookies = httpResponse.cookies();
  assertEquals(1, cookies.length);
  assertEquals("waffle", cookies[0].getName());
  assertEquals("jam!", cookies[0].getValue());
}

代码示例来源:origin: org.jodd/jodd-http

/**
 * Reads cookies from response and adds to cookies list.
 */
protected void readCookies(final HttpResponse httpResponse) {
  Cookie[] newCookies = httpResponse.cookies();
  for (Cookie cookie : newCookies) {
    cookies.add(cookie.getName(), cookie);
  }
}

相关文章