本文整理汇总了Java中com.meterware.httpunit.HttpUnitUtils.parseContentTypeHeader方法的典型用法代码示例。如果您正苦于以下问题:Java HttpUnitUtils.parseContentTypeHeader方法的具体用法?Java HttpUnitUtils.parseContentTypeHeader怎么用?Java HttpUnitUtils.parseContentTypeHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.meterware.httpunit.HttpUnitUtils
的用法示例。
在下文中一共展示了HttpUnitUtils.parseContentTypeHeader方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ServletUnitHttpRequest
import com.meterware.httpunit.HttpUnitUtils; //导入方法依赖的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 );
}
}
示例2: setContentType
import com.meterware.httpunit.HttpUnitUtils; //导入方法依赖的package包/类
/**
* Sets the content type of the response the server sends to
* the client. The content type may include the type of character
* encoding used, for example, <code>text/html; charset=ISO-8859-4</code>.
*
* <p>You can only use this method once, and you should call it
* before you obtain a <code>PrintWriter</code> or
* {@link ServletOutputStream} object to return a response.
**/
public void setContentType( String type ) {
String[] typeAndEncoding = HttpUnitUtils.parseContentTypeHeader( type );
_contentType = typeAndEncoding[0];
if (typeAndEncoding[1] != null) _encoding = typeAndEncoding[1];
if (_encoding.equalsIgnoreCase( HttpUnitUtils.DEFAULT_CHARACTER_SET )) {
setHeader( "Content-Type", type );
} else {
setHeader( "Content-Type", _contentType + "; charset=" + _encoding );
}
}
示例3: setContentType
import com.meterware.httpunit.HttpUnitUtils; //导入方法依赖的package包/类
/**
* Sets the content type of the response the server sends to
* the client. The content type may include the type of character
* encoding used, for example, <code>text/html; charset=ISO-8859-4</code>.
*
* <p>You can only use this method once, and you should call it
* before you obtain a <code>PrintWriter</code> or
* {@link ServletOutputStream} object to return a response.
**/
public void setContentType( String type ) {
String[] typeAndEncoding = HttpUnitUtils.parseContentTypeHeader( type );
_contentType = typeAndEncoding[0];
if (typeAndEncoding[1] != null) _encoding = typeAndEncoding[1];
}