本文整理汇总了Java中org.apache.http.util.EncodingUtils.getAsciiString方法的典型用法代码示例。如果您正苦于以下问题:Java EncodingUtils.getAsciiString方法的具体用法?Java EncodingUtils.getAsciiString怎么用?Java EncodingUtils.getAsciiString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.util.EncodingUtils
的用法示例。
在下文中一共展示了EncodingUtils.getAsciiString方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBasicAuthentication
import org.apache.http.util.EncodingUtils; //导入方法依赖的package包/类
@Test
public void testBasicAuthentication() throws Exception {
final UsernamePasswordCredentials creds =
new UsernamePasswordCredentials("testuser", "testpass");
final Header challenge = new BasicHeader(AUTH.WWW_AUTH, "Basic realm=\"test\"");
final BasicScheme authscheme = new BasicScheme();
authscheme.processChallenge(challenge);
final HttpRequest request = new BasicHttpRequest("GET", "/");
final HttpContext context = new BasicHttpContext();
final Header authResponse = authscheme.authenticate(creds, request, context);
final String expected = "Basic " + EncodingUtils.getAsciiString(
Base64.encodeBase64(EncodingUtils.getAsciiBytes("testuser:testpass")));
Assert.assertEquals(AUTH.WWW_AUTH_RESP, authResponse.getName());
Assert.assertEquals(expected, authResponse.getValue());
Assert.assertEquals("test", authscheme.getRealm());
Assert.assertTrue(authscheme.isComplete());
Assert.assertFalse(authscheme.isConnectionBased());
}
示例2: testBasicProxyAuthentication
import org.apache.http.util.EncodingUtils; //导入方法依赖的package包/类
@Test
public void testBasicProxyAuthentication() throws Exception {
final UsernamePasswordCredentials creds =
new UsernamePasswordCredentials("testuser", "testpass");
final Header challenge = new BasicHeader(AUTH.PROXY_AUTH, "Basic realm=\"test\"");
final BasicScheme authscheme = new BasicScheme();
authscheme.processChallenge(challenge);
final HttpRequest request = new BasicHttpRequest("GET", "/");
final HttpContext context = new BasicHttpContext();
final Header authResponse = authscheme.authenticate(creds, request, context);
final String expected = "Basic " + EncodingUtils.getAsciiString(
Base64.encodeBase64(EncodingUtils.getAsciiBytes("testuser:testpass")));
Assert.assertEquals(AUTH.PROXY_AUTH_RESP, authResponse.getName());
Assert.assertEquals(expected, authResponse.getValue());
Assert.assertEquals("test", authscheme.getRealm());
Assert.assertTrue(authscheme.isComplete());
Assert.assertFalse(authscheme.isConnectionBased());
}
示例3: loadPage
import org.apache.http.util.EncodingUtils; //导入方法依赖的package包/类
private String loadPage(String file) throws Exception {
InputStream inputStream = null;
byte[] buffer = null;
try {
inputStream = getResources().getAssets().open(file);
buffer = new byte[inputStream.available()];
inputStream.read(buffer);
inputStream.close();
return EncodingUtils.getAsciiString(buffer);
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (Exception exception) { }
}
}
}
示例4: loadPage
import org.apache.http.util.EncodingUtils; //导入方法依赖的package包/类
private String loadPage(String file) throws Exception {
InputStream is = null;
byte[] buffer;
try {
is = getResources().getAssets().open(file);
buffer = new byte[is.available()];
is.read(buffer);
is.close();
return EncodingUtils.getAsciiString(buffer);
} finally {
if (is != null) {
try {
is.close();
} catch (Exception e) {
}
}
}
}
示例5: getResponse
import org.apache.http.util.EncodingUtils; //导入方法依赖的package包/类
/**
* Returns the response that has been generated after shrinking the
* array if required and base64 encodes the response.
*
* @return The response as above.
*/
String getResponse() {
byte[] resp;
if (messageContents.length > currentOutputPosition) {
byte[] tmp = new byte[currentOutputPosition];
for (int i = 0; i < currentOutputPosition; i++) {
tmp[i] = messageContents[i];
}
resp = tmp;
} else {
resp = messageContents;
}
return EncodingUtils.getAsciiString(Base64.encodeBase64(resp));
}
示例6: getResponse
import org.apache.http.util.EncodingUtils; //导入方法依赖的package包/类
/**
* Returns the response that has been generated after shrinking the
* array if required and base64 encodes the response.
*
* @return The response as above.
*/
String getResponse() {
final byte[] resp;
if (messageContents.length > currentOutputPosition) {
final byte[] tmp = new byte[currentOutputPosition];
System.arraycopy(messageContents, 0, tmp, 0, currentOutputPosition);
resp = tmp;
} else {
resp = messageContents;
}
return EncodingUtils.getAsciiString(Base64.encode(resp, Base64.NO_WRAP));
}
示例7: getResponse
import org.apache.http.util.EncodingUtils; //导入方法依赖的package包/类
/**
* Returns the response that has been generated after shrinking the
* array if required and base64 encodes the response.
*
* @return The response as above.
*/
String getResponse() {
final byte[] resp;
if (messageContents.length > currentOutputPosition) {
final byte[] tmp = new byte[currentOutputPosition];
System.arraycopy(messageContents, 0, tmp, 0, currentOutputPosition);
resp = tmp;
} else {
resp = messageContents;
}
return EncodingUtils.getAsciiString(Base64.encodeBase64(resp));
}
示例8: testValidMethodCalls
import org.apache.http.util.EncodingUtils; //导入方法依赖的package包/类
private void testValidMethodCalls(String cmdString, Object... parameters) throws Exception {
ViSearchHttpClientImpl client = new ViSearchHttpClientImpl(validEndpoint, validAccessKey, validSecretKey, mockedHttpClient);
ArgumentCaptor<HttpUriRequest> argument = ArgumentCaptor.forClass(HttpUriRequest.class);
CloseableHttpResponse response = mock(CloseableHttpResponse.class);
Header[] headers = { new BasicHeader("test-param", "123") };
when(response.getAllHeaders()).thenReturn(headers);
when(response.getEntity()).thenReturn(new StringEntity("test"));
when(mockedHttpClient.execute(argument.capture())).thenReturn(response);
CommandType cmd = determineCommandType(cmdString);
switch (cmd) {
case GET:
client.get((String) parameters[0], (Multimap<String, String>) parameters[1]);
break;
case POST:
client.post((String) parameters[0], (Multimap<String, String>) parameters[1]);
break;
case POST_IMAGE_01:
client.postImage((String) parameters[0], (Multimap<String, String>) parameters[1], (File) parameters[2]);
break;
case POST_IMAGE_02:
client.postImage((String) parameters[0], (Multimap<String, String>) parameters[1], (InputStream) parameters[2], (String) parameters[3]);
break;
default:
break;
}
HttpUriRequest request = argument.getValue();
Header[] headerArray = request.getAllHeaders();
String expected = "Basic " + EncodingUtils.getAsciiString(Base64.encodeBase64(EncodingUtils.getAsciiBytes(validAccessKey + ":" + validSecretKey)));
boolean isFound = false;
for (int i = 0; i < headerArray.length; i++) {
if (headerArray[i].getValue().equals(expected)) {
isFound = true; // found credentials
break;
}
}
assertTrue(isFound);
}
示例9: encode
import org.apache.http.util.EncodingUtils; //导入方法依赖的package包/类
/**
* Escape and encode a given string with allowed characters not to be
* escaped and a given charset.
*
* @param unescaped a string
* @param allowed allowed characters not to be escaped
* @param charset the charset
* @return the escaped string
*/
public static String encode(String unescaped, BitSet allowed,
String charset) throws HttpException {
byte[] rawdata = URLCodec.encodeUrl(allowed,
EncodingUtils.getBytes(unescaped, charset));
return EncodingUtils.getAsciiString(rawdata);
}
示例10: encode
import org.apache.http.util.EncodingUtils; //导入方法依赖的package包/类
/**
* Escape and encode a given string with allowed characters not to be
* escaped and a given charset.
*
* @param unescaped a string
* @param allowed allowed characters not to be escaped
* @param charset the charset
* @return the escaped string
*/
public static String encode(String unescaped, BitSet allowed,
String charset) throws URIException {
byte[] rawdata = URLCodec.encodeUrl(allowed,
EncodingUtils.getBytes(unescaped, charset));
return EncodingUtils.getAsciiString(rawdata);
}
示例11: encode
import org.apache.http.util.EncodingUtils; //导入方法依赖的package包/类
/**
* Escape and encode a given string with allowed characters not to be
* escaped and a given charset.
*
* @param unescaped a string
* @param allowed allowed characters not to be escaped
* @param charset the charset
* @return the escaped string
*/
public static String encode(String unescaped, BitSet allowed,
String charset) throws HttpException {
byte[] rawdata = URLCodec.encodeUrl(allowed,
EncodingUtils.getBytes(unescaped, charset));
return EncodingUtils.getAsciiString(rawdata);
}