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:nl.coralic.beta.sms.utils.http.HttpHandler.java

private static List<NameValuePair> createPostData(HashMap<String, String> arguments) throws Exception {
    List<NameValuePair> postdata = new ArrayList<NameValuePair>();
    if (arguments != null) {
        for (String key : arguments.keySet()) {
            postdata.add(new BasicNameValuePair(key, arguments.get(key)));
        }/* w  w  w  . j a va 2s .  c o  m*/
        return postdata;
    }
    throw new Exception("No arguments");
}

From source file:com.intel.iotkitlib.utils.Utilities.java

public static List<NameValuePair> addHttpHeaders(List<NameValuePair> headers, String headerName,
        String headerValue) {//from w  w  w  . ja  v  a2s  . c  o m
    //add header name-value pair
    headers.add(new BasicNameValuePair(headerName, headerValue));
    return headers;
}

From source file:att.jaxrs.client.Content_tagCollection.java

public static Content_tagCollection getContentTagsWithID(long content_id) {
    List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
    urlParameters.add(new BasicNameValuePair("content_id", Long.toString(content_id)));

    Content_tagCollection collectionCT = new Content_tagCollection();

    try {/*from w  w  w .j  a  v  a2  s.c  om*/
        System.out.println("invoking getTagsWithID: " + content_id);
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost post = new HttpPost(Constants.SELECT_WITH_KEY_CONTENT_TAG_RESOURCE);
        post.setEntity(new UrlEncodedFormEntity(urlParameters));
        HttpResponse result = httpClient.execute(post);
        System.out.println(Constants.RESPONSE_STATUS_CODE + result);
        String resultStr = Util.getStringFromInputStream(result);

        collectionCT = Marshal.unmarshal(Content_tagCollection.class, resultStr);

    } catch (Exception e) {
        e.printStackTrace();

    }

    return collectionCT;
}

From source file:net.mandaria.radioreddit.apis.RedditAPI.java

public static RedditAccount login(Context context, String username, String password) {
    RedditAccount account = new RedditAccount();

    try {//  w w w.  j  a v a2s  . c o  m
        String url = context.getString(R.string.reddit_login) + "/" + username;

        // post values
        ArrayList<NameValuePair> post_values = new ArrayList<NameValuePair>();

        BasicNameValuePair user = new BasicNameValuePair("user", username);
        post_values.add(user);

        BasicNameValuePair passwd = new BasicNameValuePair("passwd", password);
        post_values.add(passwd);

        BasicNameValuePair api_type = new BasicNameValuePair("api_type", "json");
        post_values.add(api_type);

        String outputLogin = HTTPUtil.post(context, url, post_values);

        JSONTokener reddit_login_tokener = new JSONTokener(outputLogin);
        JSONObject reddit_login_json = new JSONObject(reddit_login_tokener);

        JSONObject json = reddit_login_json.getJSONObject("json");

        if (json.getJSONArray("errors").length() > 0) {
            String error = json.getJSONArray("errors").getJSONArray(0).getString(1);

            account.ErrorMessage = error;
        } else {
            JSONObject data = json.getJSONObject("data");

            // success!
            String cookie = data.getString("cookie");
            String modhash = data.getString("modhash");

            account.Username = username;
            account.Cookie = cookie;
            account.Modhash = modhash;
            account.ErrorMessage = "";
        }
    } catch (Exception ex) {
        // We fail to get the streams...
        CustomExceptionHandler ceh = new CustomExceptionHandler(context);
        ceh.sendEmail(ex);

        ex.printStackTrace();

        account.ErrorMessage = ex.toString();
    }

    return account;
}

From source file:com.core.ServerConnector.java

public static String post(String endpoint, Map<String, String> params) throws Exception {
    String result = null;//  w ww  .  j  a  va  2s.co  m
    HttpParams httpParameters = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParameters, 5000);
    HttpConnectionParams.setSoTimeout(httpParameters, 10000);
    HttpClient httpclient = new DefaultHttpClient(httpParameters);
    HttpPost httppost = new HttpPost(endpoint);
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
    Iterator<Entry<String, String>> iterator = params.entrySet().iterator();
    while (iterator.hasNext()) {
        Entry<String, String> param = iterator.next();
        nameValuePairs.add(new BasicNameValuePair(param.getKey(), param.getValue()));
    }
    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    HttpResponse response = httpclient.execute(httppost);
    HttpEntity entity = response.getEntity();
    if (entity != null) {
        InputStream instream = entity.getContent();
        result = SystemUtil.convertStreamToString(instream);

        instream.close();
    }

    return result;
}

From source file:org.epop.dataprovider.googlescholar.GoogleScholarGetterFromId.java

static List<Literature> getFromId(String userId) {
    // http://scholar.google.it/citations?user=q21xxm4AAAAJ&pagesize=100
    List<NameValuePair> qparams = new ArrayList<NameValuePair>();
    qparams.add(new BasicNameValuePair("user", userId));
    qparams.add(new BasicNameValuePair("pagesize", "100"));

    URI uri;// w w  w . java2 s.c om
    String responseBody = null;
    try {
        uri = URIUtils.createURI("http", GOOGLE_SCHOLAR, -1, "", URLEncodedUtils.format(qparams, "UTF-8"),
                null);
        uri = new URI(uri.toString().replace("citations/?", "citations?"));
        HttpGet httpget = new HttpGet(uri);
        System.out.println(httpget.getURI());
        HttpClient httpclient = new DefaultHttpClient();
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        responseBody = httpclient.execute(httpget, responseHandler);
        //System.out.println(responseBody);
        int counter = 1;
        String newResponseBody = responseBody;
        while (newResponseBody.contains("class=\"cit-dark-link\">Next &gt;</a>")) {
            URI newUri = new URI(uri.toString() + "&cstart=" + counter * 100);
            httpget = new HttpGet(newUri);
            System.out.println(httpget.getURI());
            httpclient = new DefaultHttpClient();
            newResponseBody = httpclient.execute(httpget, responseHandler);
            //System.out.println(newResponseBody);
            responseBody = responseBody + newResponseBody;
            counter++;
        }
    } catch (URISyntaxException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    // return the result as string
    return parsePage(new StringReader(responseBody));
}

From source file:in.flipbrain.Utils.java

public static String httpPost(String uri, HashMap<String, String> params) {
    List<NameValuePair> nvps = new ArrayList<NameValuePair>();
    for (Map.Entry<String, String> entrySet : params.entrySet()) {
        String key = entrySet.getKey();
        String value = entrySet.getValue();
        nvps.add(new BasicNameValuePair(key, value));
    }//  w w  w. j a va  2  s .  co m
    String res = null;
    try {
        res = Request.Post(uri).bodyForm(nvps).execute().returnContent().asString();
        logger.debug("Response: " + res);
    } catch (IOException e) {
        logger.fatal("Failed to process request. ", e);
    }
    return res;
}

From source file:business.sendMessage.SendMessage.java

public void senTextMessage(String phone, String msg) throws TwilioRestException {

    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

    // Build a filter for the MessageList
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("Body", "Send Help I am having an " + msg + " Attack"));
    params.add(new BasicNameValuePair("To", "+1" + phone));
    params.add(new BasicNameValuePair("From", "+16179350296"));

    MessageFactory messageFactory = client.getAccount().getMessageFactory();
    Message message = messageFactory.create(params);
    System.out.println(message.getSid());
}

From source file:com.example.typetalk.request.auth.ClientCredentialsParameterTet.java

@Test
public void testEncode() {
    ClientCredentialsParameter params = new ClientCredentialsParameter("client_id", "client_secret");
    List<NameValuePair> expected = new ArrayList<>();
    expected.add(new BasicNameValuePair("client_id", "client_id"));
    expected.add(new BasicNameValuePair("client_secret", "client_secret"));
    expected.add(new BasicNameValuePair("grant_type", "client_credentials"));
    expected.add(new BasicNameValuePair("scope", "topic.read,topic.post,topic.write,topic.delete,my"));

    assertThat(params.encode(), is(expected));
}

From source file:att.jaxrs.client.Content.java

public static String addContent(Content content) {
    List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
    urlParameters.add(new BasicNameValuePair("content_id", content.getContent_id().toString()));
    urlParameters.add(new BasicNameValuePair("level", content.getLevel()));
    urlParameters.add(new BasicNameValuePair("presenter", content.getPresenter()));
    urlParameters.add(new BasicNameValuePair("reads", content.getReads()));

    String resultStr = "";

    try {//  w  w w .  jav  a 2s . co m

        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost post = new HttpPost(Constants.INSERT_CONTENT_RESOURCE);
        post.setEntity(new UrlEncodedFormEntity(urlParameters));
        HttpResponse result = httpClient.execute(post);
        System.out.println(Constants.RESPONSE_STATUS_CODE + result);
        resultStr = Util.getStringFromInputStream(result.getEntity().getContent());
        System.out.println(Constants.RESPONSE_BODY + resultStr);

    } catch (Exception e) {
        System.out.println(e.getMessage());

    }
    return resultStr;
}