use of org.apache.http.message.BasicNameValuePair in project xUtils by wyouflf.
the class URLEncodedUtils method parse.
/**
* Adds all parameters within the Scanner to the list of <code>parameters</code>.
* For example,a scanner containing the string <code>a=1&b=2&c=3</code> would
* add the {@link org.apache.http.NameValuePair NameValuePairs} a=1, b=2, and c=3 to the
* list of parameters.
*
* @param parameters List to add parameters to.
* @param scanner Input that contains the parameters to parse.
*/
public static void parse(final List<NameValuePair> parameters, final Scanner scanner) {
scanner.useDelimiter(PARAMETER_SEPARATOR);
while (scanner.hasNext()) {
String name = null;
String value = null;
String token = scanner.next();
int i = token.indexOf(NAME_VALUE_SEPARATOR);
if (i != -1) {
name = token.substring(0, i).trim();
value = token.substring(i + 1).trim();
} else {
name = token.trim();
}
parameters.add(new BasicNameValuePair(name, value));
}
}
use of org.apache.http.message.BasicNameValuePair in project jstorm by alibaba.
the class AlimonitorClient method httpPost.
private boolean httpPost(String url, String msg) {
boolean ret = false;
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
CloseableHttpResponse response = null;
try {
HttpPost request = new HttpPost(url);
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("name", monitorName));
nvps.add(new BasicNameValuePair("msg", msg));
request.setEntity(new UrlEncodedFormEntity(nvps));
response = httpClient.execute(request);
HttpEntity entity = response.getEntity();
if (entity != null) {
LOG.info(EntityUtils.toString(entity));
}
EntityUtils.consume(entity);
ret = true;
} catch (Exception e) {
LOG.error("Exception when sending http request to alimonitor", e);
} finally {
try {
if (response != null)
response.close();
httpClient.close();
} catch (Exception e) {
LOG.error("Exception when closing httpclient", e);
}
}
return ret;
}
use of org.apache.http.message.BasicNameValuePair in project robovm by robovm.
the class URLEncodedUtils method parse.
/**
* Adds all parameters within the Scanner to the list of
* <code>parameters</code>, as encoded by <code>encoding</code>. For
* example, a scanner containing the string <code>a=1&b=2&c=3</code> would
* add the {@link NameValuePair NameValuePairs} a=1, b=2, and c=3 to the
* list of parameters.
*
* @param parameters
* List to add parameters to.
* @param scanner
* Input that contains the parameters to parse.
* @param encoding
* Encoding to use when decoding the parameters.
*/
public static void parse(final List<NameValuePair> parameters, final Scanner scanner, final String encoding) {
scanner.useDelimiter(PARAMETER_SEPARATOR);
while (scanner.hasNext()) {
final String[] nameValue = scanner.next().split(NAME_VALUE_SEPARATOR);
if (nameValue.length == 0 || nameValue.length > 2)
throw new IllegalArgumentException("bad parameter");
final String name = decode(nameValue[0], encoding);
String value = null;
if (nameValue.length == 2)
value = decode(nameValue[1], encoding);
parameters.add(new BasicNameValuePair(name, value));
}
}
use of org.apache.http.message.BasicNameValuePair in project Trello-Android by chrisHoekstra.
the class TrelloService method getNotifications.
public ArrayList<NotificationVO> getNotifications() {
ArrayList<NotificationVO> result = null;
ArrayList<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
params.add(new BasicNameValuePair("key", PUBLIC_KEY));
params.add(new BasicNameValuePair("token", mToken));
HttpGet httpGet = new HttpGet(TRELLO_API_URL + "members/" + "me/" + "notifications?" + URLEncodedUtils.format(params, "UTF-8"));
HttpClient httpClient = getHttpClient();
try {
httpGet.setHeader("Accept", "application/json, text/javascript, */*; q=0.01");
httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, USER_AGENT_STRING);
HttpResponse response = httpClient.execute(httpGet, mContext);
if (response != null) {
result = mObjectMapper.readValue(mJsonFactory.createJsonParser(new InputStreamReader(response.getEntity().getContent(), "UTF-8")), new TypeReference<ArrayList<NotificationVO>>() {
});
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
use of org.apache.http.message.BasicNameValuePair in project Trello-Android by chrisHoekstra.
the class TrelloService method addCard.
public Boolean addCard(String boardListId, String name) {
Boolean result = false;
ArrayList<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
params.add(new BasicNameValuePair("key", PUBLIC_KEY));
params.add(new BasicNameValuePair("token", mToken));
params.add(new BasicNameValuePair("name", name));
params.add(new BasicNameValuePair("idList", boardListId));
HttpPost httpPost = new HttpPost(TRELLO_API_URL + "cards?" + URLEncodedUtils.format(params, "UTF-8"));
HttpClient httpClient = getHttpClient();
try {
httpPost.setHeader("Accept", "application/json, text/javascript, */*; q=0.01");
httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, USER_AGENT_STRING);
HttpResponse response = httpClient.execute(httpPost, mContext);
if (response != null) {
result = true;
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
Aggregations