use of org.apache.http.NameValuePair in project wikidata-query-rdf by wikimedia.
the class WikibaseRepository method postWithToken.
/**
* Post with a csrf token.
*
* @throws IOException if its thrown while communicating with wikibase
*/
private HttpPost postWithToken(URI uri) throws IOException {
HttpPost request = new HttpPost(uri);
List<NameValuePair> entity = new ArrayList<>();
entity.add(new BasicNameValuePair("token", csrfToken()));
request.setEntity(new UrlEncodedFormEntity(entity, Consts.UTF_8));
return request;
}
use of org.apache.http.NameValuePair in project instructure-android by instructure.
the class HttpHelpers method parseLinkHeaderResponse.
/**
* parseLinkHeaderResponse is the old way of parsing the pagination URLs out of the response.
* @param response
* @return
*/
private static APIHttpResponse parseLinkHeaderResponse(HttpResponse response) {
APIHttpResponse httpResponse = new APIHttpResponse();
// Get status code.
httpResponse.responseCode = response.getStatusLine().getStatusCode();
// Check if response is supposed to have a body
if (httpResponse.responseCode != 204) {
try {
httpResponse.responseBody = EntityUtils.toString(response.getEntity());
} catch (Exception E) {
}
}
Header[] linkHeader = response.getHeaders("Link");
for (int j = 0; j < linkHeader.length; j++) {
HeaderElement[] elements = linkHeader[j].getElements();
for (int i = 0; i < elements.length; i++) {
String first = elements[i].getName();
String last = elements[i].getValue();
// Seems to strip out the equals between name and value
String url = first + "=" + last;
if (url.startsWith("<") && url.endsWith(">")) {
url = url.substring(1, url.length() - 1);
} else {
continue;
}
for (int k = 0; k < elements[i].getParameterCount(); k++) {
NameValuePair nvp = elements[i].getParameter(k);
if (nvp.getName().equals("rel")) {
if (nvp.getValue().equals("prev")) {
httpResponse.prevURL = url;
} else if (nvp.getValue().equals("next")) {
httpResponse.nextURL = url;
} else if (nvp.getValue().equals("first")) {
httpResponse.firstURL = url;
} else if (nvp.getValue().equals("last")) {
httpResponse.lastURL = url;
}
}
}
}
}
return httpResponse;
}
use of org.apache.http.NameValuePair in project OsmAnd-tools by osmandapp.
the class BlockIO method doPostApiCall.
private Response doPostApiCall(String method, Map<String, String> params, Class<?> responseType) throws BlockIOException {
CloseableHttpClient client = HttpClients.createDefault();
HttpPost request = new HttpPost(Constants.buildUri(method, true));
List<NameValuePair> postParams = new ArrayList<NameValuePair>(2);
postParams.add(new BasicNameValuePair(Constants.Params.API_KEY, apiKey));
if (params != null) {
for (Map.Entry<String, String> entry : params.entrySet()) {
postParams.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
}
}
postParams.add(new BasicNameValuePair("priority", PRIORITY));
CloseableHttpResponse response;
try {
request.setEntity(new UrlEncodedFormEntity(postParams));
response = client.execute(request);
return getResponse(response, responseType);
} catch (IOException e) {
throw new BlockIOException("Network connectivity problem.");
}
}
use of org.apache.http.NameValuePair in project jwt by emweb.
the class AuthUtils method parseFormUrlEncoded.
static void parseFormUrlEncoded(HttpMessage response, Map<String, String[]> parameters) {
try {
StringEntity entity = new StringEntity(response.getBody(), null);
entity.setContentType(URLEncodedUtils.CONTENT_TYPE);
List<NameValuePair> valuePairs = URLEncodedUtils.parse(entity);
for (NameValuePair nvp : valuePairs) {
String[] values = new String[1];
values[0] = nvp.getValue();
parameters.put(nvp.getName(), values);
}
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.apache.http.NameValuePair in project ORCID-Source by ORCID.
the class OpenIDConnectTest method testImplicitWithNoAuthorizedGrant.
@Test
public void testImplicitWithNoAuthorizedGrant() throws URISyntaxException {
HashMap<String, String> requestParams = new HashMap<String, String>();
requestParams.put("nonce", "noMate");
// check a client without implicit fails
String clientId = getClient2ClientId();
String clientRedirectUri = getClient2RedirectUri();
String userName = getUser1OrcidId();
String userPassword = getUser1Password();
List<String> scope = Lists.newArrayList("openid");
String nope = super.getImplicitTokenResponse(clientId, scope, userName, userPassword, clientRedirectUri, requestParams, "token", true);
// check it's got a fragment
assertTrue(nope.contains("#"));
// switch to query param for ease of parsing
nope = nope.replace('#', '?');
List<NameValuePair> params = URLEncodedUtils.parse(new URI(nope), "UTF-8");
Map<String, String> map = new HashMap<String, String>();
for (NameValuePair pair : params) {
map.put(pair.getName(), pair.getValue());
}
assertEquals(map.get("error"), "invalid_client");
assertEquals(map.get("error_description"), "Unauthorized grant type: implicit");
}
Aggregations