use of org.apache.http.NameValuePair in project xUtils by wyouflf.
the class URLEncodedUtils method format.
/**
* Returns a String that is suitable for use as an <code>application/x-www-form-urlencoded</code>
* list of parameters in an HTTP PUT or HTTP POST.
*
* @param parameters The parameters to include.
* @param charset The encoding to use.
*/
public static String format(final List<? extends NameValuePair> parameters, final String charset) {
final StringBuilder result = new StringBuilder();
for (final NameValuePair parameter : parameters) {
final String encodedName = encodeFormFields(parameter.getName(), charset);
final String encodedValue = encodeFormFields(parameter.getValue(), charset);
if (result.length() > 0) {
result.append(PARAMETER_SEPARATOR);
}
result.append(encodedName);
if (encodedValue != null) {
result.append(NAME_VALUE_SEPARATOR);
result.append(encodedValue);
}
}
return result.toString();
}
use of org.apache.http.NameValuePair in project hadoop by apache.
the class PseudoAuthenticationHandler method getUserName.
private String getUserName(HttpServletRequest request) {
String queryString = request.getQueryString();
if (queryString == null || queryString.length() == 0) {
return null;
}
List<NameValuePair> list = URLEncodedUtils.parse(queryString, UTF8_CHARSET);
if (list != null) {
for (NameValuePair nv : list) {
if (PseudoAuthenticator.USER_NAME.equals(nv.getName())) {
return nv.getValue();
}
}
}
return null;
}
use of org.apache.http.NameValuePair in project robovm by robovm.
the class URLEncodedUtils method format.
/**
* Returns a String that is suitable for use as an <code>application/x-www-form-urlencoded</code>
* list of parameters in an HTTP PUT or HTTP POST.
*
* @param parameters The parameters to include.
* @param encoding The encoding to use.
*/
public static String format(final List<? extends NameValuePair> parameters, final String encoding) {
final StringBuilder result = new StringBuilder();
for (final NameValuePair parameter : parameters) {
final String encodedName = encode(parameter.getName(), encoding);
final String value = parameter.getValue();
final String encodedValue = value != null ? encode(value, encoding) : "";
if (result.length() > 0)
result.append(PARAMETER_SEPARATOR);
result.append(encodedName);
result.append(NAME_VALUE_SEPARATOR);
result.append(encodedValue);
}
return result.toString();
}
use of org.apache.http.NameValuePair in project cryptonomica by Cryptonomica.
the class TwilioUtils method sendSms.
public static Message sendSms(final String phoneNumber, final String smsMessage) throws NumberParseException, IllegalArgumentException, TwilioRestException {
checkPhoneNumber(phoneNumber);
checkSmsMessage(smsMessage);
final String accountSid = ApiKeysUtils.getApiKey("twilioAccountSid");
final String authToken = ApiKeysUtils.getApiKey("twilioAuthToken");
final String twilioPhoneNumber = ApiKeysUtils.getApiKey("twilioPhoneNumber");
// Twilio.init(accountSid, authToken);
// Message message = Message.creator(
// new PhoneNumber(phoneNumber), // To number
// new PhoneNumber(twilioPhoneNumber), // From number
// smsMessage // SMS body
// ).create();
// LOG.warning(message.toString());
TwilioRestClient client = new TwilioRestClient(accountSid, authToken);
Account account = client.getAccount();
MessageFactory messageFactory = account.getMessageFactory();
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("To", phoneNumber));
params.add(new BasicNameValuePair("From", twilioPhoneNumber));
params.add(new BasicNameValuePair("Body", smsMessage));
Message sms = messageFactory.create(params);
LOG.warning(sms.toString());
return sms;
}
use of org.apache.http.NameValuePair in project crawler4j by yasserg.
the class PageFetcher method doFormLogin.
/**
* FORM authentication<br/>
* Official Example: https://hc.apache.org/httpcomponents-client-ga/httpclient/examples/org
* /apache/http/examples/client/ClientFormLogin.java
*/
private void doFormLogin(FormAuthInfo authInfo) {
logger.info("FORM authentication for: {}", authInfo.getLoginTarget());
String fullUri = authInfo.getProtocol() + "://" + authInfo.getHost() + ":" + authInfo.getPort() + authInfo.getLoginTarget();
HttpPost httpPost = new HttpPost(fullUri);
List<NameValuePair> formParams = new ArrayList<>();
formParams.add(new BasicNameValuePair(authInfo.getUsernameFormStr(), authInfo.getUsername()));
formParams.add(new BasicNameValuePair(authInfo.getPasswordFormStr(), authInfo.getPassword()));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formParams, StandardCharsets.UTF_8);
httpPost.setEntity(entity);
try {
httpClient.execute(httpPost);
logger.debug("Successfully request to login in with user: {} to: {}", authInfo.getUsername(), authInfo.getHost());
} catch (ClientProtocolException e) {
logger.error("While trying to login to: {} - Client protocol not supported", authInfo.getHost(), e);
} catch (IOException e) {
logger.error("While trying to login to: {} - Error making request", authInfo.getHost(), e);
}
}
Aggregations