use of org.apache.http.message.BasicNameValuePair in project selenium-tests by Wikia.
the class CommonUtils method sendPost.
public static String sendPost(String apiUrl, String[][] param) {
try {
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(apiUrl);
List<NameValuePair> paramPairs = new ArrayList<NameValuePair>();
for (int i = 0; i < param.length; i++) {
paramPairs.add(new BasicNameValuePair(param[i][0], param[i][1]));
}
httpPost.setEntity(new UrlEncodedFormEntity(paramPairs));
HttpResponse response = null;
response = httpclient.execute(httpPost);
HttpEntity entity = response.getEntity();
return EntityUtils.toString(entity);
} catch (UnsupportedEncodingException e) {
PageObjectLogging.log("sendPost", e, false);
return null;
} catch (ClientProtocolException e) {
PageObjectLogging.log("sendPost", e, false);
return null;
} catch (IOException e) {
PageObjectLogging.log("sendPost", e, false);
return null;
}
}
use of org.apache.http.message.BasicNameValuePair in project appsly-android-rest by 47deg.
the class JacksonHttpFormValuesConverter method toRequestBody.
@Override
@SuppressWarnings("unchecked")
public <T> HttpEntity toRequestBody(T object, String contentType) {
Logger.d("JacksonHttpFormValuesConverter.toRequestBody: object: " + object);
try {
HttpEntity entity = null;
List<NameValuePair> vals = new ArrayList<NameValuePair>();
if (HeaderUtils.CONTENT_TYPE_FORM_URL_ENCODED.startsWith(contentType)) {
Map<String, Object> props = mapper.convertValue(object, Map.class);
for (Map.Entry<String, Object> formPartEntry : props.entrySet()) {
if (formPartEntry.getValue() != null) {
vals.add(new BasicNameValuePair(formPartEntry.getKey(), formPartEntry.getValue().toString()));
}
}
entity = new UrlEncodedFormEntity(vals);
} else if (HeaderUtils.CONTENT_TYPE_MULTIPART_FORM_DATA.startsWith(contentType)) {
Map<String, Object> props = mapper.convertValue(object, Map.class);
MultipartEntity multipartEntity = new MultipartEntity(null);
for (Map.Entry<String, Object> formPartEntry : props.entrySet()) {
if (formPartEntry.getValue() != null) {
if (formPartEntry.getValue() instanceof FileFormField) {
FileFormField fileFormField = (FileFormField) formPartEntry.getValue();
multipartEntity.addPart(formPartEntry.getKey(), fileFormField.getFile(), fileFormField.getContentType());
} else {
multipartEntity.addPart(formPartEntry.getKey(), formPartEntry.getValue().toString());
}
}
}
entity = multipartEntity;
}
return entity;
} catch (UnsupportedEncodingException e) {
throw new SerializationException(e);
}
}
use of org.apache.http.message.BasicNameValuePair in project SeaStar by 13120241790.
the class RequestParams method createMultipartEntity.
private HttpEntity createMultipartEntity(ResponseHandlerInterface progressHandler) throws IOException {
SimpleMultipartEntity entity = new SimpleMultipartEntity(progressHandler);
entity.setIsRepeatable(isRepeatable);
// Add string params
for (ConcurrentHashMap.Entry<String, String> entry : urlParams.entrySet()) {
entity.addPart(entry.getKey(), entry.getValue());
}
// Add non-string params
List<BasicNameValuePair> params = getParamsList(null, urlParamsWithObjects);
for (BasicNameValuePair kv : params) {
entity.addPart(kv.getName(), kv.getValue());
}
// Add stream params
for (ConcurrentHashMap.Entry<String, StreamWrapper> entry : streamParams.entrySet()) {
StreamWrapper stream = entry.getValue();
if (stream.inputStream != null) {
entity.addPart(entry.getKey(), stream.name, stream.inputStream, stream.contentType);
}
}
// Add file params
for (ConcurrentHashMap.Entry<String, FileWrapper> entry : fileParams.entrySet()) {
FileWrapper fileWrapper = entry.getValue();
entity.addPart(entry.getKey(), fileWrapper.file, fileWrapper.contentType);
}
return entity;
}
use of org.apache.http.message.BasicNameValuePair in project DrupalCloud by INsReady.
the class JSONServerClient method userLogin.
@Override
public String userLogin(String username, String password) throws ServiceNotAvailableException {
BasicNameValuePair[] parameters = new BasicNameValuePair[2];
parameters[0] = new BasicNameValuePair("username", username);
parameters[1] = new BasicNameValuePair("password", password);
return call("user.login", parameters);
}
use of org.apache.http.message.BasicNameValuePair in project DrupalCloud by INsReady.
the class JSONServerClient method flagIsFlagged.
@Override
public boolean flagIsFlagged(String flagName, int contentId, int uid) throws ServiceNotAvailableException {
BasicNameValuePair[] parameters = new BasicNameValuePair[3];
parameters[0] = new BasicNameValuePair("flag_name", flagName);
parameters[1] = new BasicNameValuePair("content_id", String.valueOf(contentId));
parameters[2] = new BasicNameValuePair("uid", String.valueOf(uid));
String result = call("flag.is_flagged", parameters);
JSONObject jso;
try {
jso = new JSONObject(result);
boolean flag = jso.getBoolean("#data");
return flag;
} catch (JSONException e) {
e.printStackTrace();
}
return false;
}
Aggregations