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

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

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

HttpRequest.cookies介绍

[英]Sets cookies to the request.
[中]将cookies设置为请求。

代码示例

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

/**
   * Add cookies to the request.
   */
  protected void addCookies(final HttpRequest httpRequest) {
    // prepare all cookies
    List<Cookie> cookiesList = new ArrayList<>();

    if (!cookies.isEmpty()) {
      for (Map.Entry<String, Cookie> cookieEntry : cookies) {
        cookiesList.add(cookieEntry.getValue());
      }

      httpRequest.cookies(cookiesList.toArray(new Cookie[0]));
    }
  }
}

代码示例来源: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

/**
   * Add cookies to the request.
   */
  protected void addCookies(final HttpRequest httpRequest) {
    // prepare all cookies
    List<Cookie> cookiesList = new ArrayList<>();

    if (!cookies.isEmpty()) {
      for (Map.Entry<String, Cookie> cookieEntry : cookies) {
        cookiesList.add(cookieEntry.getValue());
      }

      httpRequest.cookies(cookiesList.toArray(new Cookie[0]));
    }
  }
}

代码示例来源:origin: com.liferay.launchpad/api-client

.collect(Collectors.toList());
httpRequest.cookies(
  cookies.toArray(new jodd.http.Cookie[cookies.size()]));

相关文章