7

I'm trying to use a Mashape api, I have added the following libraries (jars) unirest, httpasyncclient, httpclient, httpmime, org.json, commons-longging, httpcore to my project.

I'm trying to run...

HttpResponse<JsonNode> response = Unirest.post("https://life-left.p.mashape.com/time-left")
.header("X-Mashape-Key", "1NZITOdDGqmshKRAEdDbX0tp0WV2p1RR5SSjsnQYQIVwrANkhC")
.header("Content-Type", "application/x-www-form-urlencoded")
.field("birth", "22 April 1977")
.field("gender", "female")
.asJson();

But I get this exception...

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/nio/reactor/IOReactorException
at com.mashape.unirest.http.HttpClientHelper.prepareRequest(HttpClientHelper.java:154)
at com.mashape.unirest.http.HttpClientHelper.request(HttpClientHelper.java:131)
at com.mashape.unirest.request.BaseRequest.asJson(BaseRequest.java:68)
at test.Test.main(Test.java:24)
Caused by: java.lang.ClassNotFoundException: org.apache.http.nio.reactor.IOReactorException
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)

I've tried googling around but I can't find out what is wrong.

Any help would be appreciated.

OneTwo
  • 2,291
  • 6
  • 33
  • 55
  • 1
    You need to add nio api jar in your project library. Go through the URL and download it and ad this in your project libraries. [link](www.java2s.com/Code/JarDownload/httpcore/httpcore-nio-4.1-beta2.jar.zip) – Altmish-E-Azam Nov 03 '14 at 13:03
  • It's part of the HttpCore 4.3.3 binarys you can download from Apache. – Tommy Dec 04 '14 at 13:35

1 Answers1

9

I had same problem but resolved after adding following dependency in my project pom.xml file

    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpcore-nio</artifactId>
        <version>4.4.3</version>
    </dependency>
Dharmesh Gohil
  • 324
  • 2
  • 6