I have been trying to use REST API in Java for the webservice FRED an NLP tool. Below is my code which I have been trying to run.
package lcr;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
public class TestGet{
public static void main(String[] args) {
try {
Client client = Client.create();
WebResource webResource = client
.resource("http://wit.istc.cnr.it/stlab-tools/fred/");
ClientResponse response = webResource.accept("Miles Davis was an american jazz musician"
, "application/rdf+xml")
.get(ClientResponse.class);
if (response.getStatus() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ response.getStatus());
}
String output = response.getEntity(String.class);
System.out.println("Output from Server .... \n");
System.out.println(output);
} catch (Exception e) {
e.printStackTrace();
}
}
}
and the output:
java.lang.RuntimeException: Failed : HTTP error code : 400
at lcr.TestGet.main(TestGet.java:22)
I have tried to lookup for the error itself (400 = Bad Request), but seem not to understand what it means
You're calling the service incorrectly. Try:
ClientResponse response = webResource.queryParam("text", "Miles Davis was an american jazz musician").accept("application/rdf+xml").get(ClientResponse.class);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.