简体   繁体   English

Monkeylearn 使用 Java 响应状态码 423

[英]Monkeylearn responds with status code 423 using Java

I am trying to connect to Monkey Learn URL but the error that I get is as follows:我正在尝试连接到 Monkey Learn URL,但我得到的错误如下:

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)构建成功(总时间:2 秒)

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:您在 Authorization 请求标头中缺少某些内容,该值应以“Token”开头,请将其更改为如下所示:

connection.setRequestProperty("Authorization",
                              "Token d6589857b53d9b732591b84c16016ac8dd1a4c43");

Finally, note that you posted your API key, please revoke it as soon as posible using monkeylearn web UI.最后,请注意您发布了您的 API 密钥,请尽快使用monkeylearn Web UI 撤销它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java代码,用于使用套接字连接获取多个IP,端口的状态 - Java code for getting the status of multiple IP,Port using socket connection 从 Java 使用 LocalStack 时获取 AmazonKinesisException 状态代码:502 - Getting an AmazonKinesisException Status Code: 502 when using LocalStack from Java Java代码检查防火墙状态 - Java code to check the status of firewall 使用Java RestAssured创建POST请求,返回状态码422 - Create POST request, using Java RestAssured, returns status code 422 使用java连接到站点和POST,HTTP状态代码200 - Using java to connect to a site and POST, HTTP Status Code 200 使用Java通过代理检查请求的状态码 - Check status code for a request made via proxy using java Java HttpURLConnection 状态码 302 - Java HttpURLConnection status code 302 安装了Java 7,但终端响应版本6 - installed java 7 but terminal responds with version 6 为什么我只在使用 Java HTTP 客户端时得到 HTTP 响应状态码 451? - Why do I get HTTP Response Status Code 451 only when using the Java HTTP Client? 在 Java 11 及更高版本中使用 HttpClient 时如何跟踪 HTTP 303 状态代码? - How to follow-through on HTTP 303 status code when using HttpClient in Java 11 and later?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM