I am trying to connect to Monkey Learn URL but the error that I get is as follows:
java.io.IOException: Server returned HTTP response code: 423 for URL: https://api.monkeylearn.com/v2/classifiers/cl_rFrQ66gZ/classify/
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1245)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:234)
at app.Main.main(Main.java:51)
BUILD SUCCESSFUL (total time: 2 seconds)
What is the problem?
Here is my sample code:
//Create connection
url = new URL ("https://api.monkeylearn.com/v2/classifiers/cl_rFrQ66gZ/classify/");
connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Authorization",
"d6589857b53d9b732591b84c16016ac8dd1a4c43");
connection.setRequestProperty("Content-Type",
"application/json");
connection.setUseCaches (false);
connection.setDoInput(true);
connection.setDoOutput(true);
//Send request
OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
wr.write ("{\"text_list\": [\"some text to test\", \"some more text\"]}");
wr.flush ();
wr.close ();
You can get a detailed error message by printing the response body.
You're missing something in the Authorization request header the value should start with "Token ", change it for something like this:
connection.setRequestProperty("Authorization",
"Token d6589857b53d9b732591b84c16016ac8dd1a4c43");
Finally, note that you posted your API key, please revoke it as soon as posible using monkeylearn web UI.
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.