本文整理汇总了Java中com.meterware.httpunit.WebClient类的典型用法代码示例。如果您正苦于以下问题:Java WebClient类的具体用法?Java WebClient怎么用?Java WebClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WebClient类属于com.meterware.httpunit包,在下文中一共展示了WebClient类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ServletUnitHttpRequest
import com.meterware.httpunit.WebClient; //导入依赖的package包/类
/**
* Constructs a ServletUnitHttpRequest from a WebRequest object.
**/
ServletUnitHttpRequest( ServletMetaData servletRequest, WebRequest request, ServletUnitContext context, Dictionary clientHeaders, byte[] messageBody ) throws MalformedURLException {
if (context == null) throw new IllegalArgumentException( "Context must not be null" );
_servletRequest = servletRequest;
_request = request;
_context = context;
_headers = new WebClient.HeaderDictionary();
_headers.addEntries( clientHeaders );
_headers.addEntries( request.getHeaders() );
_messageBody = messageBody;
_secure = request.getURL().getProtocol().equalsIgnoreCase( "https" );
_contentType = (String) _headers.get( "Content-Type" );
if (_headers.get( "Content-Length") == null) _headers.put( "Content-Length", Integer.toString( messageBody.length ) );
_requestContext = new RequestContext( request.getURL() );
if (_messageBody != null && (_contentType == null || _contentType.indexOf( "x-www-form-urlencoded" ) >= 0 )) {
_requestContext.loadParameters( new String( _messageBody ) );
}
}
示例2: ServletUnitHttpRequest
import com.meterware.httpunit.WebClient; //导入依赖的package包/类
/**
* Constructs a ServletUnitHttpRequest from a WebRequest object.
**/
ServletUnitHttpRequest( ServletMetaData servletRequest, WebRequest request, ServletUnitContext context, Dictionary clientHeaders, byte[] messageBody ) throws MalformedURLException {
if (context == null) throw new IllegalArgumentException( "Context must not be null" );
_servletRequest = servletRequest;
_request = request;
_context = context;
_headers = new WebClient.HeaderDictionary();
_headers.addEntries( clientHeaders );
_headers.addEntries( request.getHeaders() );
setCookiesFromHeader( _headers );
_messageBody = messageBody;
_protocol=request.getURL().getProtocol().toLowerCase();
_secure = _protocol.endsWith("s" );
_requestContext = new RequestContext( request.getURL() );
String contentTypeHeader = (String) _headers.get( "Content-Type" );
if (contentTypeHeader != null) {
String[] res = HttpUnitUtils.parseContentTypeHeader( contentTypeHeader );
_contentType = res[0];
_charset = res[1];
_requestContext.setMessageEncoding( _charset );
}
if (_headers.get( "Content-Length") == null) _headers.put( "Content-Length", Integer.toString( messageBody.length ) );
boolean setBody=
// pre [ 1509117 ] getContentType()
// _messageBody != null && (_contentType == null || _contentType.indexOf( "x-www-form-urlencoded" ) >= 0 );
// patch version:
_messageBody != null && (contentTypeHeader == null || contentTypeHeader.indexOf( "x-www-form-urlencoded" ) >= 0 );
if (setBody) {
_requestContext.setMessageBody( _messageBody );
}
}
示例3: testConfigObject
import com.meterware.httpunit.WebClient; //导入依赖的package包/类
public void testConfigObject() throws Exception {
final String resourceName = "something/interesting";
ServletRunner sr = new ServletRunner();
sr.registerServlet( resourceName, ConfigServlet.class.getName() );
WebClient wc = sr.newClient();
WebResponse response = wc.getResponse( "http://localhost/" + resourceName );
assertNotNull( "No response received", response );
assertEquals( "content type", "text/plain", response.getContentType() );
assertEquals( "servlet name is " + ConfigServlet.class.getName(), response.getText() );
}