use of org.apache.http.message.BasicNameValuePair in project Notes by MiCode.
the class GTaskClient method postRequest.
private JSONObject postRequest(JSONObject js) throws NetworkFailureException {
if (!mLoggedin) {
Log.e(TAG, "please login first");
throw new ActionFailureException("not logged in");
}
HttpPost httpPost = createHttpPost();
try {
LinkedList<BasicNameValuePair> list = new LinkedList<BasicNameValuePair>();
list.add(new BasicNameValuePair("r", js.toString()));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list, "UTF-8");
httpPost.setEntity(entity);
// execute the post
HttpResponse response = mHttpClient.execute(httpPost);
String jsString = getResponseContent(response.getEntity());
return new JSONObject(jsString);
} catch (ClientProtocolException e) {
Log.e(TAG, e.toString());
e.printStackTrace();
throw new NetworkFailureException("postRequest failed");
} catch (IOException e) {
Log.e(TAG, e.toString());
e.printStackTrace();
throw new NetworkFailureException("postRequest failed");
} catch (JSONException e) {
Log.e(TAG, e.toString());
e.printStackTrace();
throw new ActionFailureException("unable to convert response content to jsonobject");
} catch (Exception e) {
Log.e(TAG, e.toString());
e.printStackTrace();
throw new ActionFailureException("error occurs when posting request");
}
}
use of org.apache.http.message.BasicNameValuePair in project PneumaticCraft by MineMaarten.
the class PastebinHandler method loginInternal.
public boolean loginInternal(String userName, String password) {
HttpPost httppost = new HttpPost("http://pastebin.com/api/api_login.php");
List<NameValuePair> params = new ArrayList<NameValuePair>(3);
params.add(new BasicNameValuePair("api_dev_key", DEV_KEY));
params.add(new BasicNameValuePair("api_user_name", userName));
params.add(new BasicNameValuePair("api_user_password", password));
try {
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream instream = entity.getContent();
userKey = IOUtils.toString(instream, "UTF-8");
if (userKey.startsWith("Bad API request")) {
Log.warning("User tried to log in into pastebin, it responded with the following: " + userKey);
userKey = null;
return false;
}
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
use of org.apache.http.message.BasicNameValuePair in project Anki-Android by Ramblurr.
the class Feedback method addTimestamp.
// Run in AsyncTask
private static void addTimestamp(List<NameValuePair> pairs) {
Date ts = new Date();
df1.setTimeZone(TimeZone.getTimeZone("UTC"));
String reportsentutc = String.format("%s", df1.format(ts));
String reportsenttzoffset = String.format("%s", df2.format(ts));
String reportsenttz = String.format("%s", localTz.getID());
pairs.add(new BasicNameValuePair("reportsentutc", reportsentutc));
pairs.add(new BasicNameValuePair("reportsenttzoffset", reportsenttzoffset));
pairs.add(new BasicNameValuePair("reportsenttz", reportsenttz));
}
use of org.apache.http.message.BasicNameValuePair in project aws-iam-ldap-bridge by denismo.
the class IAMAccountPasswordValidator method verifyIAMPassword.
@Override
public boolean verifyIAMPassword(Entry user, String pw) throws LdapInvalidAttributeValueException, LdapAuthenticationException {
try {
LOG.debug("Verifying {} {} with accessKey <hidden> and secretKey <hidden>", "user", user.get("uid").getString());
HttpClient client = new SystemDefaultHttpClient();
HttpPost post = new HttpPost("https://signin.aws.amazon.com/oauth");
post.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.65 Safari/537.36");
post.setHeader("Referer", "https://signin.aws.amazon.com/oauth");
List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
urlParameters.add(new BasicNameValuePair("client_id", "arn:aws:iam::015428540659:user/homepage"));
urlParameters.add(new BasicNameValuePair("isIAMUser", "1"));
urlParameters.add(new BasicNameValuePair("account", user.get("accountNumber").getString()));
urlParameters.add(new BasicNameValuePair("username", user.get("uid").getString()));
urlParameters.add(new BasicNameValuePair("password", pw));
urlParameters.add(new BasicNameValuePair("Action", "login"));
urlParameters.add(new BasicNameValuePair("redirect_uri", "https://console.aws.amazon.com/console/home?state=hashArgs%23&isauthcode=true"));
urlParameters.add(new BasicNameValuePair("forceMobileApp", ""));
urlParameters.add(new BasicNameValuePair("forceMobileLayout", ""));
urlParameters.add(new BasicNameValuePair("mfaLoginFailure", ""));
urlParameters.add(new BasicNameValuePair("RemainingExpiryPeriod", ""));
urlParameters.add(new BasicNameValuePair("mfacode", ""));
urlParameters.add(new BasicNameValuePair("next_mfacode", ""));
post.setEntity(new UrlEncodedFormEntity(urlParameters, Charset.forName("UTF-8")));
HttpResponse response = client.execute(post);
return containsHeaders(response, "aws-account-alias", "aws-creds");
} catch (IOException e) {
LOG.error("Exception validating password for " + user.get("uid").getString(), e);
return false;
} catch (RuntimeException t) {
LOG.error("Exception validating password for " + user.get("uid").getString(), t);
throw t;
}
}
use of org.apache.http.message.BasicNameValuePair in project moco by dreamhead.
the class MocoWebTest method should_match_form_value.
@Test
public void should_match_form_value() throws Exception {
server.post(eq(form("name"), "dreamhead")).response("foobar");
running(server, new Runnable() {
@Override
public void run() throws Exception {
String content = Post(root()).bodyForm(new BasicNameValuePair("name", "dreamhead")).execute().returnContent().asString();
assertThat(content, is("foobar"));
}
});
}
Aggregations