Example usage for org.apache.http.message BasicNameValuePair BasicNameValuePair

List of usage examples for org.apache.http.message BasicNameValuePair BasicNameValuePair

Introduction

In this page you can find the example usage for org.apache.http.message BasicNameValuePair BasicNameValuePair.

Prototype

public BasicNameValuePair(String str, String str2) 

Source Link

Usage

From source file:asynctasks.LoadTaskTicketDataAsync.java

@Override
protected JSONObject doInBackground(String... params) {

    SessionUser session = new SessionUser(context);

    List<NameValuePair> passer = new ArrayList<NameValuePair>();
    passer.add(new BasicNameValuePair("tag", "gettask"));
    passer.add(new BasicNameValuePair("currentstaff", session.userDetails().get("email")));
    passer.add(new BasicNameValuePair("task", params[0]));
    passer.add(new BasicNameValuePair("t_id", params[1]));
    passer.add(new BasicNameValuePair("tk_id", params[2]));
    JSONObject json = jSerial.getJSONFromUrl(loadDataUrl, "POST", passer);
    return json;//from   w w w . j a va2 s. c  o  m
}

From source file:com.ibm.watson.developer_cloud.util.RequestUtilTest.java

/**
 * Test format query string.//  w ww .  j av a2s . c  om
 */
@Test
public void testFormatQueryString() {
    List<NameValuePair> query = new ArrayList<NameValuePair>();
    query.add(new BasicNameValuePair("q", "1"));
    query.add(new BasicNameValuePair("foo", "bar"));

    String queryString = RequestUtil.formatQueryString(query, "UTF-8");

    Assert.assertNotNull(queryString);
    Assert.assertEquals("q=1&foo=bar", queryString);
}

From source file:com.mopaas_mobile.parser.OrganizationParser.java

public static Map<String, Object> doParse(String source) throws JSONException {
    JSONObject jsonObject = new JSONObject(source);
    ArrayList<BasicNameValuePair> spacelist = new ArrayList<BasicNameValuePair>();
    Map<String, Object> resultmap = new HashMap<String, Object>();
    if (!jsonObject.isNull("code"))
        resultmap.put("code", jsonObject.getString("code"));
    JSONArray jsonlistorg = jsonObject.getJSONArray("organizations");
    JSONObject jsonItem = jsonlistorg.getJSONObject(0);
    if (!jsonItem.isNull("guid"))
        resultmap.put("guid", jsonItem.getString("guid"));
    JSONArray jsonlistitem = jsonItem.getJSONArray("spaceses");
    for (int j = 0; j < jsonlistitem.length(); j++) {
        JSONObject jsonapace = jsonlistitem.getJSONObject(j);
        spacelist.add(new BasicNameValuePair(jsonapace.getString("guid"), jsonapace.getString("name")));
    }/* w w  w  .  j a va  2s .com*/
    resultmap.put("list", spacelist);
    return resultmap;

}

From source file:com.cats.version.utils.Utils.java

public static String postMsgAndGet(String msg) {
    HttpPost request = new HttpPost(UserPreference.getInstance().getUrl());
    List<NameValuePair> parameters = new ArrayList<NameValuePair>();
    parameters.add(new BasicNameValuePair("msg", msg));

    try {/*from   w  w  w  . j ava  2  s .c o m*/
        UrlEncodedFormEntity formEntiry = new UrlEncodedFormEntity(parameters, IVersionConstant.CHARSET_UTF8);
        request.setEntity(formEntiry);
        HttpResponse response = client.execute(request);
        if (response.getStatusLine().getStatusCode() == 200) {
            return EntityUtils.toString(response.getEntity(), IVersionConstant.CHARSET_UTF8);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:au.edu.anu.portal.portlets.basiclti.support.HttpSupport.java

/**
 * Make a POST request with the given Map of parameters to be encoded
 * @param address   address to POST to/*  w  ww  .  j  a  v  a2 s .com*/
 * @param params   Map of params to use as the form parameters
 * @return
 */
public static String doPost(String address, Map<String, String> params) {

    HttpClient httpclient = new DefaultHttpClient();

    try {

        HttpPost httppost = new HttpPost(address);

        List<NameValuePair> formparams = new ArrayList<NameValuePair>();

        for (Map.Entry<String, String> entry : params.entrySet()) {
            formparams.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
        }
        UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, HTTP.UTF_8);

        httppost.setEntity(entity);

        HttpResponse response = httpclient.execute(httppost);
        String responseContent = EntityUtils.toString(response.getEntity());

        return responseContent;

    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        httpclient.getConnectionManager().shutdown();
    }

    return null;
}

From source file:br.com.atmatech.sac.webService.WebServiceAtivacao.java

public Boolean login(String url, String user, String password, String cnpj) throws IOException {
    Boolean chave = false;//w  w w. j a v a 2  s.  c o  m
    HttpPost post = new HttpPost(url);
    boolean result = false;
    /* Configura os parmetros do POST */
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    nameValuePairs.add(new BasicNameValuePair("login", user));
    nameValuePairs.add(new BasicNameValuePair("senha", password));
    post.setEntity(new UrlEncodedFormEntity(nameValuePairs, Consts.UTF_8));

    HttpResponse response = client.execute(post);

    EntityUtils.consume(response.getEntity());
    HttpGet get = new HttpGet("http://atma.serveftp.com/atma/view/nav/header_chave.php?cnpj=" + cnpj);
    response = client.execute(get);

    BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
    String line;
    FileWriter out = new FileWriter("./ativacao.html");
    PrintWriter gravarArq = new PrintWriter(out);
    while ((line = rd.readLine()) != null) {
        gravarArq.print(line + "\n");
        chave = true;
    }
    out.close();
    return chave;
}

From source file:asynctasks.AddTicketDataAsync.java

@Override
protected JSONObject doInBackground(String... params) {

    SessionUser session = new SessionUser(context);
    HashMap<String, String> user = session.userDetails();
    String staffentered = user.get("email");

    List<NameValuePair> passer = new ArrayList<NameValuePair>();
    passer.add(new BasicNameValuePair("tag", "addticket"));
    passer.add(new BasicNameValuePair("ticket", params[0]));
    passer.add(new BasicNameValuePair("name", params[1]));
    passer.add(new BasicNameValuePair("date", params[2]));
    passer.add(new BasicNameValuePair("cartype", params[3]));
    passer.add(new BasicNameValuePair("model", params[4]));
    passer.add(new BasicNameValuePair("color", params[5]));
    passer.add(new BasicNameValuePair("license", params[6]));
    passer.add(new BasicNameValuePair("park", params[7]));
    passer.add(new BasicNameValuePair("key", params[8]));
    passer.add(new BasicNameValuePair("staff", staffentered));

    JSONObject json = jSerial.getJSONFromUrl(addTicketUrl, "POST", passer);

    return json;/* ww  w . j  a v  a2  s .  co m*/
}

From source file:edgeserver.Publicacao.java

public void publica(String urlLogin, String urlInsertDado) throws Exception {
    // make sure cookies is turn on
    CookieHandler.setDefault(new CookieManager());

    Date datapublicacao = new Date();

    HTTPClient http = new HTTPClient();

    List<NameValuePair> postp = new ArrayList<>();
    postp.add(new BasicNameValuePair("login", "huberto"));
    postp.add(new BasicNameValuePair("password", "99766330"));

    http.sendPost(urlLogin, postp);//  w ww.jav  a  2 s  .  c om

    List<NameValuePair> GatewayParams = new ArrayList<>();
    GatewayParams.add(new BasicNameValuePair("publicacao_servidorborda", Integer.toString(this.servidorborda)));
    GatewayParams.add(new BasicNameValuePair("publicacao_sensor", Integer.toString(this.sensor)));
    GatewayParams.add(new BasicNameValuePair("publicacao_datacoleta", this.datacoleta.toString()));
    GatewayParams.add(new BasicNameValuePair("publicacao_datapublicacao",
            new Timestamp(datapublicacao.getTime()).toString()));
    GatewayParams.add(new BasicNameValuePair("publicacao_valorcoletado", Float.toString(this.valorcoletado)));

    String result = http.GetPageContent(urlInsertDado, GatewayParams);
}

From source file:com.netdimensions.client.Commands.java

public static Command<List<Record>> getRecords(final String onBehalfOf) {
    final List<NameValuePair> parameters = new ArrayList<NameValuePair>();

    if (onBehalfOf != null) {
        parameters.add(new BasicNameValuePair("onBehalfOf", onBehalfOf));
    }/* ww w . j a  v  a  2s.c o m*/

    return new Command<List<Record>>("records", false, parameters, Record.PARSER);
}

From source file:futbol.five.com.singleton.Sms.java

public void enviarMensaje(List numbers, String body) throws TwilioRestException {
    String number;/*from   w  ww  .  j  a  va  2 s  . co  m*/
    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);
    if (numbers.size() > 0) {
        for (int i = 0; i < numbers.size(); i++) {
            number = numbers.get(i).toString();

            // Build the parameters 
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("To", "+51" + number));
            params.add(new BasicNameValuePair("From", "+15005550006"));
            params.add(new BasicNameValuePair("Body", body));

            MessageFactory messageFactory = client.getAccount().getMessageFactory();
            Message message = messageFactory.create(params);
            System.out.println(message.getSid() + " N:" + number + " Mennsaje: " + body);
        }
    } else {
        System.out.println("La lista de numeros esta vacio");
    }
}