Search in sources :

Example 36 with NameValuePair

use of org.apache.http.NameValuePair in project tdi-studio-se by Talend.

the class palodimension method rename.

public void rename(String strDimensionNewName) throws paloexception {
    if (null != strDimensionNewName && strDimensionNewName.length() > 0 && !strDimensionName.equals(strDimensionNewName)) {
        List<NameValuePair> qparams = new ArrayList<NameValuePair>();
        qparams.add(new BasicNameValuePair("sid", this.plConn.getPaloToken()));
        qparams.add(new BasicNameValuePair("database", String.valueOf(lDatabaseId)));
        qparams.add(new BasicNameValuePair("dimension", String.valueOf(this.iDimensionId)));
        qparams.add(new BasicNameValuePair("new_name", strDimensionNewName));
        try {
            HttpEntity entity = this.plConn.sendToServer(qparams, "/dimension/rename");
            CSVReader csv = new CSVReader(entity.getContent(), ';', "UTF-8");
            csv.setQuoteChar('"');
            csv.readNext();
            this.strDimensionName = csv.get(1);
            csv.close();
            entity.consumeContent();
        } catch (Exception e) {
            throw new paloexception(e.getMessage());
        }
    }
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) HttpEntity(org.apache.http.HttpEntity) CSVReader(com.talend.csv.CSVReader) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList)

Example 37 with NameValuePair

use of org.apache.http.NameValuePair in project voltdb by VoltDB.

the class HTTPUtils method callProcOverJSON.

public static String callProcOverJSON(String procName, ParameterSet pset, String username, String password, boolean preHash, boolean admin, CloseableHttpClient httpclient, HttpPost httppost) throws Exception {
    // Call insert
    String paramsInJSON = pset.toJSONString();
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("Procedure", procName));
    params.add(new BasicNameValuePair("Parameters", paramsInJSON));
    if (username != null) {
        params.add(new BasicNameValuePair("User", username));
    }
    if (password != null) {
        if (preHash) {
            params.add(new BasicNameValuePair("Hashedpassword", getHashedPasswordForHTTPVar(password)));
        } else {
            params.add(new BasicNameValuePair("Password", password));
        }
    }
    if (admin) {
        params.add(new BasicNameValuePair("admin", "true"));
    }
    return callProcOverJSONRaw(params, httpclient, httppost);
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList)

Example 38 with NameValuePair

use of org.apache.http.NameValuePair 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;
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpPost(org.apache.http.client.methods.HttpPost) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) HttpEntity(org.apache.http.HttpEntity) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) UnsupportedEncodingException(java.io.UnsupportedEncodingException) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) IOException(java.io.IOException) ClientProtocolException(org.apache.http.client.ClientProtocolException) BasicNameValuePair(org.apache.http.message.BasicNameValuePair)

Example 39 with NameValuePair

use of org.apache.http.NameValuePair in project ats-framework by Axway.

the class HttpClient method performPostRequest.

/**
     * Perform HTTP POST request based on the host and port specified before
     *
     * @param requestedHostRelativeUrl location/query without host and port like: "/my_dir/res?myParam=1"
     * @param needResponse whether caller needs the contents returned from this request
     * @param paramsMap map of parameters to be sent with this POST request
     * @throws FileTransferException
     */
public String performPostRequest(String requestedHostRelativeUrl, boolean needResponse, HashMap<String, String> paramsMap) throws FileTransferException {
    checkClientInitialized();
    final String getUrl = constructGetUrl(requestedHostRelativeUrl);
    log.info("Performing POST request to: " + getUrl);
    HttpPost postMethod = new HttpPost(getUrl);
    addRequestHeaders(postMethod);
    if (paramsMap != null && paramsMap.size() > 0) {
        List<NameValuePair> parameters = new ArrayList<NameValuePair>(paramsMap.size());
        for (Entry<String, String> paramEntry : paramsMap.entrySet()) {
            log.info("Add parameter " + paramEntry.getKey() + " and value: " + paramEntry.getValue());
            parameters.add(new BasicNameValuePair(paramEntry.getKey(), paramEntry.getValue()));
        }
        UrlEncodedFormEntity sendEntity = null;
        try {
            sendEntity = new UrlEncodedFormEntity(parameters, "UTF-8");
        } catch (UnsupportedEncodingException ex) {
            throw new FileTransferException(ex);
        }
        postMethod.setEntity(sendEntity);
    }
    return (String) processHttpRequest(postMethod, needResponse, true);
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) FileTransferException(com.axway.ats.common.filetransfer.FileTransferException) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity)

Example 40 with NameValuePair

use of org.apache.http.NameValuePair in project UltimateAndroid by cymcsg.

the class HttpUtilsAsync method uploadFiles.

public static void uploadFiles(String url, List<NameValuePair> paramsList, String fileParams, List<File> files, AsyncHttpResponseHandler responseHandler) {
    SyncHttpClient syncHttpClient = new SyncHttpClient();
    RequestParams params = new RequestParams();
    try {
        if (BasicUtils.judgeNotNull(paramsList)) {
            for (NameValuePair nameValuePair : paramsList) {
                params.put(nameValuePair.getName(), nameValuePair.getValue());
            }
        }
        if (BasicUtils.judgeNotNull(files))
            params.put(fileParams, files);
    } catch (Exception e) {
        Logs.e(e, "");
    }
    syncHttpClient.setTimeout(TIME_OUT);
    syncHttpClient.post(url, params, responseHandler);
}
Also used : NameValuePair(org.apache.http.NameValuePair) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

NameValuePair (org.apache.http.NameValuePair)725 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)603 ArrayList (java.util.ArrayList)486 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)265 HttpPost (org.apache.http.client.methods.HttpPost)228 HttpResponse (org.apache.http.HttpResponse)157 IOException (java.io.IOException)131 HttpEntity (org.apache.http.HttpEntity)116 Test (org.junit.Test)85 URI (java.net.URI)82 Map (java.util.Map)73 HashMap (java.util.HashMap)69 HttpGet (org.apache.http.client.methods.HttpGet)67 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)61 UnsupportedEncodingException (java.io.UnsupportedEncodingException)60 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)57 URISyntaxException (java.net.URISyntaxException)54 URIBuilder (org.apache.http.client.utils.URIBuilder)52 Document (org.jsoup.nodes.Document)51 HttpClient (org.apache.http.client.HttpClient)50