Here are some lines of code that works with netbeans. note the imports
import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.conn.ProxySelectorRoutePlanner;
import org.apache.http.conn.params.ConnRoutePNames;
***SNIP
HttpGet method = null;
HttpHost targetHost = null;
HttpHost proxy = null;
DefaultHttpClient cli = new DefaultHttpClient();
method = new HttpGet(url);
HttpResponse resp = null;
HttpEntity ent = null;
resp = cli.execute(method);
ent = resp.getEntity();
On Fri, Mar 9, 2012 at 9:15 AM, Gregory Orton <[email protected]> wrote:
> Hi there,
>
>
>
> I have been working on a piece of software in Netbeans for a while,
> successfully using the JDK built in library "HttpUrlConnection". However,
> for various reasons when I try to use HttpClient in my software, I am
> running into constant issues.
>
>
>
> I download the both the *.jar files and the source code from the
> hc.apache.org website and in netbeans I loaded the JAR files into my
> libraries. Following this, I followed the tuotorial for a "basic" request in
> my code and at the top of the document "import org.apache.http.client.*;"
>
>
>
> Unfortunately with the example code:
>
>
>
> HttpClient httpclient = new DefaultHttpClient();
>
> HttpGet httpget = new HttpGet("http://localhost/");
>
> HttpResponse response = httpclient.execute(httpget);
>
>
>
> Netbeans starts complaining about several things:
>
>
>
> 1. It says that HttpClient and DefaultHttpClient are incompatible types
> and so I cannot assign one to another.
>
> 2. So if I set HttpClient to be DefaultHttpClient then I get another
> error and it decides that httpclient has no .execute() method defined for
> it.
>
> 3. If I cast (HttpClient) to from Default in the first assignation, I
> can bypass this, but then the system rejects my call of execute() saying
> that the httpget is not a valid property to pass to the execute command.
>
>
>
> There is obviously some very strange behaviour going on here - it's clearly
> my netbeans set-up or I am missing something pretty serious in my importing
> of these files. Will httpclient work without Maven and importing everything
> it needs? I really need some help getting httpclient into my netbeans
> project. I've done so much reading and asking around on places like stack
> overflow, but I honestly am at the end of my tether.
>
>
>
> Any help you can offer would be appreciated.
>
>
>
> Kind regards,
>
>
>
> Gregory
>
>
>
>
>
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]