本文整理汇总了Java中org.apache.http.HeaderElement.getParameterByName方法的典型用法代码示例。如果您正苦于以下问题:Java HeaderElement.getParameterByName方法的具体用法?Java HeaderElement.getParameterByName怎么用?Java HeaderElement.getParameterByName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.HeaderElement
的用法示例。
在下文中一共展示了HeaderElement.getParameterByName方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFileNameFromHttpResponse
import org.apache.http.HeaderElement; //导入方法依赖的package包/类
public static String getFileNameFromHttpResponse(final HttpResponse response) {
if (response == null) return null;
String result = null;
Header header = response.getFirstHeader("Content-Disposition");
if (header != null) {
for (HeaderElement element : header.getElements()) {
NameValuePair fileNamePair = element.getParameterByName("filename");
if (fileNamePair != null) {
result = fileNamePair.getValue();
// try to get correct encoding str
result = CharsetUtils.toCharset(result, HTTP.UTF_8, result.length());
break;
}
}
}
return result;
}
示例2: getCharsetFromHttpResponse
import org.apache.http.HeaderElement; //导入方法依赖的package包/类
public static String getCharsetFromHttpResponse(final HttpResponse response) {
if (response == null) return null;
String result = null;
Header header = response.getEntity().getContentType();
if (header != null) {
for (HeaderElement element : header.getElements()) {
NameValuePair charsetPair = element.getParameterByName("charset");
if (charsetPair != null) {
result = charsetPair.getValue();
break;
}
}
}
boolean isSupportedCharset = false;
if (!TextUtils.isEmpty(result)) {
try {
isSupportedCharset = Charset.isSupported(result);
} catch (Throwable e) {
}
}
return isSupportedCharset ? result : null;
}
示例3: create
import org.apache.http.HeaderElement; //导入方法依赖的package包/类
private static ContentType create(final HeaderElement helem) {
String mimeType = helem.getName();
String charset = null;
NameValuePair param = helem.getParameterByName("charset");
if (param != null) {
charset = param.getValue();
}
return create(mimeType, charset);
}
示例4: getCharsetFromHttpRequest
import org.apache.http.HeaderElement; //导入方法依赖的package包/类
public static Charset getCharsetFromHttpRequest(final HttpRequestBase request) {
if (request == null) return null;
String charsetName = null;
Header header = request.getFirstHeader("Content-Type");
if (header != null) {
for (HeaderElement element : header.getElements()) {
NameValuePair charsetPair = element.getParameterByName("charset");
if (charsetPair != null) {
charsetName = charsetPair.getValue();
break;
}
}
}
boolean isSupportedCharset = false;
if (!TextUtils.isEmpty(charsetName)) {
try {
isSupportedCharset = Charset.isSupported(charsetName);
} catch (Throwable e) {
}
}
return isSupportedCharset ? Charset.forName(charsetName) : null;
}
示例5: testExplictContractorParams
import org.apache.http.HeaderElement; //导入方法依赖的package包/类
@Test
public void testExplictContractorParams() throws Exception {
final HttpEntity entity = MultipartEntityBuilder.create()
.setLaxMode()
.setBoundary("whatever")
.setCharset(MIME.UTF8_CHARSET)
.build();
Assert.assertNull(entity.getContentEncoding());
Assert.assertNotNull(entity.getContentType());
final Header header = entity.getContentType();
final HeaderElement[] elems = header.getElements();
Assert.assertNotNull(elems);
Assert.assertEquals(1, elems.length);
final HeaderElement elem = elems[0];
Assert.assertEquals("multipart/form-data", elem.getName());
final NameValuePair p1 = elem.getParameterByName("boundary");
Assert.assertNotNull(p1);
Assert.assertEquals("whatever", p1.getValue());
final NameValuePair p2 = elem.getParameterByName("charset");
Assert.assertNotNull(p2);
Assert.assertEquals("UTF-8", p2.getValue());
}
示例6: testImplictContractorParams
import org.apache.http.HeaderElement; //导入方法依赖的package包/类
@Test
public void testImplictContractorParams() throws Exception {
final HttpEntity entity = MultipartEntityBuilder.create().build();
Assert.assertNull(entity.getContentEncoding());
Assert.assertNotNull(entity.getContentType());
final Header header = entity.getContentType();
final HeaderElement[] elems = header.getElements();
Assert.assertNotNull(elems);
Assert.assertEquals(1, elems.length);
final HeaderElement elem = elems[0];
Assert.assertEquals("multipart/form-data", elem.getName());
final NameValuePair p1 = elem.getParameterByName("boundary");
Assert.assertNotNull(p1);
final String boundary = p1.getValue();
Assert.assertNotNull(boundary);
Assert.assertTrue(boundary.length() >= 30);
Assert.assertTrue(boundary.length() <= 40);
final NameValuePair p2 = elem.getParameterByName("charset");
Assert.assertNull(p2);
}
示例7: checkForInbox
import org.apache.http.HeaderElement; //导入方法依赖的package包/类
public String checkForInbox(String sourceUrl, InboxDiscoveryMethod source) throws InterruptedException, IOException {
if(source==null) {
String ret=checkForInbox(sourceUrl, InboxDiscoveryMethod.HTTP_HEADER);
if(ret==null)
ret=checkForInbox(sourceUrl, InboxDiscoveryMethod.RDF_MICRODATA);
return ret;
}
FetchRequest fetched = httpFetcher.fetch(new UrlRequest(sourceUrl));
// for(Header h: fetched.getResponse().getAllHeaders()) {
// System.out.println(h.getName()+" - "+h.getValue());
// }
if(source!=null) {
switch (source) {
case HTTP_HEADER:
for(Header h: fetched.getResponse().getHeaders("Link")) {
// System.out.println(h.getName()+" - "+h.getValue());
HeaderElement[] hElements = BasicHeaderValueParser.INSTANCE.parseElements(h.getValue(), null);
for(HeaderElement hEl: hElements) {
// System.out.println( "v "+hEl.getValue());
// System.out.println( "n "+hEl.getName());
// System.out.println( hEl.getParameterCount());
NameValuePair hElParam=hEl.getParameterByName("rel");
if(hElParam!=null && hElParam.getValue().equals("http://www.w3.org/ns/ldp#inbox")) {
// System.out.println( hElParam.getName()+" -- "+hElParam.getValue() );
return hEl.getName().replaceFirst("^\\s*<\\s*", "").replaceFirst("\\s*>\\s*$", "");
}
}
}
System.out.println();
break;
case RDF_MICRODATA:
try {
String[] inboxUrl=new String[1];
any23.extract(fetched.getContent().asString(), sourceUrl, fetched.getContent().getType().getMimeType(), fetched.getContent().getType().getCharset().name(), new CountingTripleHandler() {
@Override
public void receiveTriple(Resource arg0, IRI arg1, Value arg2, IRI arg3, ExtractionContext arg4)
throws TripleHandlerException {
if(inboxUrl[0]!=null)
return;
// System.out.println("Triple: "+ arg0.toString());
// System.out.println("1 : "+ arg1.toString());
// System.out.println("2: "+ arg2.toString());
// System.out.println("3: "+ arg3);
if(arg1!=null && arg1.stringValue().equals("http://www.w3.org/ns/ldp#inbox"))
inboxUrl[0]=arg2.stringValue();
}
});
return inboxUrl[0];
} catch (ExtractionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// System.out.println(
// fetched.getContent().asString()
// );
break;
}
} else {
}
return null;
}