本文整理汇总了Java中org.apache.http.NameValuePair.getValue方法的典型用法代码示例。如果您正苦于以下问题:Java NameValuePair.getValue方法的具体用法?Java NameValuePair.getValue怎么用?Java NameValuePair.getValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.NameValuePair
的用法示例。
在下文中一共展示了NameValuePair.getValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFileNameFromHttpResponse
import org.apache.http.NameValuePair; //导入方法依赖的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.NameValuePair; //导入方法依赖的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: parseHeader
import org.apache.http.NameValuePair; //导入方法依赖的package包/类
public HeaderElement parseHeader(
final CharArrayBuffer buffer,
final ParserCursor cursor) throws ParseException {
if (buffer == null) {
throw new IllegalArgumentException("Char array buffer may not be null");
}
if (cursor == null) {
throw new IllegalArgumentException("Parser cursor may not be null");
}
NameValuePair nvp = parseNameValuePair(buffer, cursor);
List<NameValuePair> params = new ArrayList<NameValuePair>();
while (!cursor.atEnd()) {
NameValuePair param = parseNameValuePair(buffer, cursor);
params.add(param);
}
return new BasicHeaderElement(
nvp.getName(),
nvp.getValue(), params.toArray(new NameValuePair[params.size()]));
}
示例4: getContentCharSet
import org.apache.http.NameValuePair; //导入方法依赖的package包/类
/**
* Obtains character set of the entity, if known.
*
* @param entity must not be null
* @return the character set, or null if not found
* @throws ParseException if header elements cannot be parsed
* @throws IllegalArgumentException if entity is null
*
* @deprecated (4.1.3) use {@link ContentType#getOrDefault(HttpEntity)}
*/
@Deprecated
public static String getContentCharSet(final HttpEntity entity) throws ParseException {
if (entity == null) {
throw new IllegalArgumentException("HTTP entity may not be null");
}
String charset = null;
if (entity.getContentType() != null) {
HeaderElement values[] = entity.getContentType().getElements();
if (values.length > 0) {
NameValuePair param = values[0].getParameterByName("charset");
if (param != null) {
charset = param.getValue();
}
}
}
return charset;
}
示例5: getParameter
import org.apache.http.NameValuePair; //导入方法依赖的package包/类
/**
* Extract a query string parameter without triggering http parameters
* processing by the servlet container.
*
* @param request the request
* @param name the parameter to get the value.
* @return the parameter value, or <code>NULL</code> if the parameter is not
* defined.
* @throws IOException thrown if there was an error parsing the query string.
*/
public static String getParameter(HttpServletRequest request, String name)
throws IOException {
List<NameValuePair> list = URLEncodedUtils.parse(request.getQueryString(),
UTF8_CHARSET);
if (list != null) {
for (NameValuePair nv : list) {
if (name.equals(nv.getName())) {
return nv.getValue();
}
}
}
return null;
}
示例6: getDoAs
import org.apache.http.NameValuePair; //导入方法依赖的package包/类
@VisibleForTesting
static String getDoAs(HttpServletRequest request) {
List<NameValuePair> list = URLEncodedUtils.parse(request.getQueryString(),
UTF8_CHARSET);
if (list != null) {
for (NameValuePair nv : list) {
if (DelegationTokenAuthenticatedURL.DO_AS.
equalsIgnoreCase(nv.getName())) {
return nv.getValue();
}
}
}
return null;
}
示例7: getCourseListings
import org.apache.http.NameValuePair; //导入方法依赖的package包/类
@Override
public void getCourseListings() throws MalformedURLException {
// From the home page, retrieve all links to current courses
// We also need to remove any links present in the course data block to prevent announcements
// from being interpreted as classes
WebElement simpleTable = action.waitForElement(By.xpath("//*[@id=\"_3_1termCourses_noterm\"]/ul"));
List<WebElement> links = simpleTable.findElements(By.tagName("a"));
List<WebElement> courseDataBlocks = simpleTable.findElements(By.className("courseDataBlock"));
for (WebElement we : courseDataBlocks) {
links.removeAll(we.findElements(By.tagName("a")));
}
CourseListing[] cls = new CourseListing[links.size()];
for (int i = 0; i < links.size(); i++) {
cls[i] = new CourseListing();
cls[i].course_name = links.get(i).getText();
String course_url = links.get(i).getAttribute("href");
cls[i].base_url = course_url;
try {
List<NameValuePair> params;
params = URLEncodedUtils.parse(new URI(course_url), java.nio.charset.StandardCharsets.UTF_8);
//Find course_id str
for(NameValuePair nvp : params)
{
if(nvp.getName().equals("course_id"))
{
cls[i].course_id = nvp.getValue();
break;
}
}
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
addSubGrabber(cls);
}
示例8: URLGet
import org.apache.http.NameValuePair; //导入方法依赖的package包/类
/**
* GET List<NameValuePair>请求
*
* @param pathUrl
* @param params
* @return
*/
public static String URLGet(String pathUrl, List<NameValuePair> params) {
String queryString = "";
StringBuilder repString = new StringBuilder();
try {
String path = pathUrl;
String keyValue;
if (null != params && params.size() > 0) {
for (NameValuePair nvp : params) {
String key = nvp.getName();
keyValue = nvp.getValue();
if (null != keyValue && !"".equals(keyValue)) {
queryString = queryString + key + "=" + keyValue + "&";
}
}
}
if (!"".equals(queryString)) {
path = path + "?" + queryString;
}
HttpsURLConnection.setDefaultHostnameVerifier(ignoreHostnameVerifier);
HttpsURLConnection connection = (HttpsURLConnection) (new URL(path)).openConnection();
// Prepare SSL Context
TrustManager[] tm = {ignoreCertificationTrustManger};
// SSLContext sslContext = SSLContext.getInstance("SSL", "SunJSSE");
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, tm, new java.security.SecureRandom());
// 从上述SSLContext对象中得到SSLSocketFactory对象
SSLSocketFactory ssf = sslContext.getSocketFactory();
connection.setSSLSocketFactory(ssf);
InputStreamReader isr = new InputStreamReader(connection.getInputStream(), "utf-8");
BufferedReader br = new BufferedReader(isr);
String s;
while (null != (s = br.readLine())) {
repString.append(s);
}
isr.close();
connection.disconnect();
} catch (Exception ex) {
log.error("调用链接失败:pathUrl:" + pathUrl + "queryString:" + queryString);
ex.printStackTrace();
} finally {
log.info(repString.toString());
}
return repString.toString();
}
示例9: getProperty
import org.apache.http.NameValuePair; //导入方法依赖的package包/类
/**
* MSSQL driver do not return password, so we need to parse it manually
* @param property
* @param connectionString
* @return
*/
protected static String getProperty(String property, String connectionString) {
String ret = null;
if (property != null && !property.isEmpty() && connectionString != null && !connectionString.isEmpty()) {
for (NameValuePair param : URLEncodedUtils.parse(connectionString, StandardCharsets.UTF_8, SEPARATORS)) {
if(property.equals(param.getName())){
ret = param.getValue();
break;
}
}
}
return ret;
}
示例10: create
import org.apache.http.NameValuePair; //导入方法依赖的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);
}
示例11: estimateNameValuePairLen
import org.apache.http.NameValuePair; //导入方法依赖的package包/类
/**
* Estimates the length of a formatted name-value pair.
*
* @param nvp the name-value pair to format, or <code>null</code>
*
* @return a length estimate, in number of characters
*/
protected int estimateNameValuePairLen(final NameValuePair nvp) {
if (nvp == null)
return 0;
int result = nvp.getName().length(); // name
final String value = nvp.getValue();
if (value != null) {
// assume quotes, but no escaped characters
result += 3 + value.length(); // ="value"
}
return result;
}
示例12: getParam
import org.apache.http.NameValuePair; //导入方法依赖的package包/类
public String getParam(String key) {
for (Iterator<NameValuePair> i = this.params.iterator(); i.hasNext(); ) {
NameValuePair nv = i.next();
if (nv.getName().equals(key)) {
return nv.getValue();
}
}
return "";
}
示例13: getContentTypeCharset
import org.apache.http.NameValuePair; //导入方法依赖的package包/类
public String getContentTypeCharset(String defaultCharset) {
List<String> values = getHeader(Http.Headers.CONTENT_TYPE);
if (values!=null) {
for (String value: values) {
HeaderElement[] headerElements = BasicHeaderValueParser.parseElements(value, (HeaderValueParser) null);
if (headerElements!=null && headerElements.length>0) {
NameValuePair charsetPair = headerElements[0].getParameterByName("charset");
if (charsetPair!=null) {
return charsetPair.getValue();
}
}
}
}
return defaultCharset;
}
示例14: getAuthCode
import org.apache.http.NameValuePair; //导入方法依赖的package包/类
private static String getAuthCode(String location) throws URISyntaxException {
URIBuilder uriBuilder = new URIBuilder(location);
String authCode = null;
for (NameValuePair queryParam : uriBuilder.getQueryParams())
if (queryParam.getName().equals(AUTH_CODE))
authCode = queryParam.getValue();
return authCode;
}
示例15: getUserName
import org.apache.http.NameValuePair; //导入方法依赖的package包/类
private String getUserName(HttpServletRequest request) {
List<NameValuePair> list = URLEncodedUtils.parse(request.getQueryString(), UTF8_CHARSET);
if (list != null) {
for (NameValuePair nv : list) {
if (PseudoAuthenticator.USER_NAME.equals(nv.getName())) {
return nv.getValue();
}
}
}
return null;
}