httppost is not solved in my class in my application

Asked

Viewed 107 times

1

I can’t import class from org.apache.http.conn on my Eclipse app.

This is my class:

package br.com.cadastro.cadastrocompleto.suporte;

import java.io.IOException;

public class WebClient {

    private String url;

    public WebClient(String url){
        this.url = url;
    }

    public void post(String json){
        try {
            HttpPost post = new HttpPost(url);
            post.setEntity(new StringEntity(json));
            post.setHeader("Accept", "application/json");
            post.setHeader("Content-type", "application/json");

            HttpClient httpClient = new HttpClient();
            HttpResponse response = httpClient.execute(post);

            String jsonDeResposta = EntityUtils.toString(response.getEntity());

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

What can I do about it?

EDIT

It looks like this in the Eclipse:

  • How do you import the library?

  • I’ll send you a print of what’s going on so you can understand better. I click on the red to import and Eclipse cannot resolve type Httppost http://imgur.com/vmxm9N0

  • Exactly! He belongs to a library . should be downloaded and added to the project! Follow how to do

  • I downloaded httpcomponents-client-android-4.3.5.1 from the Apache Foundation website but cannot find a jar file with the library

  • it is a zip? send the link you downloaded! so it is easier

  • @Brunocésar worked right here. I was downloading src, and then I downloaded the file . bin and came the files .jar. Thanks.

  • @Felipedeaquinonascimento ok, includes an answer to not only leave in comment

Show 2 more comments

1 answer

1


You can add libraries in many ways. It is available in public repository, so it is used , can add it like this:

<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient-android</artifactId>
    <version>4.3.5.1</version>
</dependency>

If use , simply state it as follows:

compile 'org.apache.httpcomponents:httpclient-android:4.3.5.1'

If you do not use any of these (or other) dependency manager, you can download directly from website(code here), unzip and add libraries to the directory lib which are necessary for your case.

The last alternative is to download directly from a dependency indexer, such as MVN Repository

Browser other questions tagged

You are not signed in. Login or sign up in order to post.