I want to add parameter list of (from and to time)key value pair with httpclient this are param value not a header

StackOverflow https://stackoverflow.com/questions/23494456

Question

String url = "https://api.assembla.com/v1/tasks.json";

HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);

httpGet.addHeader("Accept", "application/json");
httpGet.addHeader("Content-type", "application/json");
httpGet.addHeader("X-Api-key", "some_key");
httpGet.addHeader("X-Api-secret", "some_secret");
BufferedReader bufferedReader = null;
String jsonText = null;

HttpResponse response = httpClient.execute(httpGet);

bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

String line = "";

while ((line = bufferedReader.readLine()) != null) {
    jsonText = line;

This code gets task from date. And to date I want to make POST in GET. How can i do this?

I want to do like HTTP client POST method:

List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
urlParameters.add(new BasicNameValuePair("sn", "C02G8416DRJM"));
urlParameters.add(new BasicNameValuePair("cn", ""));
urlParameters.add(new BasicNameValuePair("locale", ""));
urlParameters.add(new BasicNameValuePair("caller", ""));
urlParameters.add(new BasicNameValuePair("num", "12345"));

post.setEntity(new UrlEncodedFormEntity(urlParameters));

HttpResponse response = client.execute(post);

Please give me the idea how to send parameter.

Was it helpful?

Solution 2

URI url = new URIBuilder().setScheme("https")
            .setHost("api.assembla.com").setPath("/v1/tasks.json")
            .setParameter("per_page", "100")
            .setParameter("from", "Some_Date")
            .setParameter("to", "Some_Date").build();

Using this we can add parameter list with httpClient heetGet method I think it may be usefull

OTHER TIPS

You have to keep params in url like below..

String url = "http://www.example.com/page?key=value";
GetMethod method = new GetMethod(url);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top