com.meterware.httpunit.WebRequest.setHeaderField()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(5.1k)|赞(0)|评价(0)|浏览(194)

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

WebRequest.setHeaderField介绍

[英]Sets the value of a header to be sent with this request. A header set here will override any matching header set in the WebClient when the request is actually sent.
[中]设置要随此请求发送的标头的值。当请求实际发送时,此处设置的头将覆盖WebClient中设置的任何匹配头。

代码示例

代码示例来源:origin: TEAMMATES/teammates

@Deprecated
private InvocationContext invokeWebRequest(String uri, String... parameters) {
  // This is not testing servlet, so any HTTP method suffices
  WebRequest request = new PostMethodWebRequest(SIMULATION_BASE_URL + uri);
  // TODO remove this portion once front-end migration is finished
  // Reason: CSRF protection is not part of action tests
  if (Const.SystemParams.PAGES_REQUIRING_ORIGIN_VALIDATION.contains(uri)) {
    request.setHeaderField("referer", SIMULATION_BASE_URL);
    String sessionId = sc.getSession(true).getId();
    String token = StringHelper.encrypt(sessionId);
    request.setParameter(Const.ParamsNames.SESSION_TOKEN, token);
  }
  Map<String, List<String>> paramMultiMap = new HashMap<>();
  for (int i = 0; i < parameters.length; i = i + 2) {
    paramMultiMap.computeIfAbsent(parameters[i], k -> new ArrayList<>()).add(parameters[i + 1]);
  }
  paramMultiMap.forEach((key, values) -> request.setParameter(key, values.toArray(new String[0])));
  try {
    return sc.newInvocation(request);
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: org.kohsuke.httpunit/httpunit

HeaderOnlyWebRequest( WebForm sourceForm, ParameterHolder parameterHolder, SubmitButton button, int x, int y ) {
  super( sourceForm, parameterHolder, button, x, y );
  setHeaderField( REFERER_HEADER_NAME, sourceForm.getBaseURL().toExternalForm() );
}

代码示例来源:origin: org.kohsuke.httpunit/httpunit

/**
 * Constructs a web request for a form submitted via a button.
 *
 * @since 1.6
 **/
protected MessageBodyWebRequest( WebForm sourceForm, ParameterHolder parameterHolder, SubmitButton button, int x, int y ) {
  super( sourceForm, parameterHolder, button, x, y );
  _mimeEncoded = parameterHolder.isSubmitAsMime();
  setHeaderField( REFERER_HEADER_NAME, sourceForm.getBaseURL().toExternalForm() );
}

代码示例来源:origin: org.kohsuke.httpunit/httpunit

HeaderOnlyWebRequest( WebRequestSource requestSource ) {
  super( requestSource, WebRequest.newParameterHolder( requestSource ) );
  setHeaderField( REFERER_HEADER_NAME, requestSource.getBaseURL().toExternalForm() );
}

代码示例来源:origin: httpunit/httpunit

/**
 * Constructs a web request using a base URL, a relative URL string, and a target.
 **/
protected WebRequest( WebResponse referer, Element sourceElement, URL urlBase, String urlString, String target ) {
  this( urlBase, urlString, referer.getFrame(), target != null ? target : referer.getBaseTarget() );
  _sourceElement = sourceElement;
  _referringPage = referer;
  setHeaderField( REFERER_HEADER_NAME, referer.getURL().toExternalForm() );
}

代码示例来源:origin: javanettasks/httpunit

/**
 * Constructs a web request using a base URL, a relative URL string, and a target.
 **/
protected WebRequest( WebResponse referer, Element sourceElement, URL urlBase, String urlString, String target ) {
  this( urlBase, urlString, referer.getFrame(), target != null ? target : referer.getBaseTarget() );
  _sourceElement = sourceElement;
  _referringPage = referer;
  setHeaderField( REFERER_HEADER_NAME, referer.getURL().toExternalForm() );
}

代码示例来源:origin: org.kohsuke.httpunit/httpunit

/**
 * Constructs a web request using a base URL, a relative URL string, and a target.
 **/
protected WebRequest( WebResponse referer, Element sourceElement, URL urlBase, String urlString, String target ) {
  this( urlBase, urlString, referer.getFrame(), target != null ? target : referer.getBaseTarget() );
  _sourceElement = sourceElement;
  _referringPage = referer;
  setHeaderField( REFERER_HEADER_NAME, referer.getURL().toExternalForm() );
}

代码示例来源:origin: org.kohsuke.httpunit/httpunit

/**
 * Constructs a web request for a form submitted via script.
 **/
protected MessageBodyWebRequest( WebForm sourceForm ) {
  super( sourceForm, WebRequest.newParameterHolder( sourceForm ) );
  _mimeEncoded = sourceForm.isSubmitAsMime();
  setHeaderField( REFERER_HEADER_NAME, sourceForm.getBaseURL().toExternalForm() );
}

代码示例来源:origin: org.kohsuke.httpunit/httpunit

RedirectWebRequest( WebResponse response ) {
  super( response.getURL(), response.getHeaderField( "Location" ), response.getFrame(), response.getFrameName() );
  if (response.getReferer() != null) setHeaderField( "Referer", response.getReferer() );
}

代码示例来源:origin: org.opencadc/cadc-test-uws

postRequest.setHeaderField("Content-Type", "application/x-www-form-urlencoded");
response = post(conversation, postRequest);

代码示例来源:origin: org.opencadc/cadc-test-uws

WebRequest postRequest = new PostMethodWebRequest(resourceUrl);
postRequest.setParameter("EXECUTIONDURATION", EXECUTIONDURATION);
postRequest.setHeaderField("Content-Type", "application/x-www-form-urlencoded");
WebResponse response = post(conversation, postRequest);

代码示例来源:origin: org.opencadc/cadc-test-uws

WebRequest postRequest = new PostMethodWebRequest(resourceUrl);
postRequest.setParameter(PARAMETER_NAME, PARAMETER_VALUE);
postRequest.setHeaderField("Content-Type", "application/x-www-form-urlencoded");
WebResponse response = post(conversation, postRequest);

相关文章