服务现在使用 java httpUrlConnection 上传附件拒绝大其余有效负载错误

问题描述

我在上传服务中事件的附件时收到以下错误

"error":{"detail":"拒绝了内容长度 = 13011091 字节的大型 REST 负载。最大允许:10485760 字节。","message":"读取请求时出现异常"},"status":"失败"}

代码如下:

   JSONObject AttachmentData = new JSONObject();
    AttachmentData.put("agent",this.getAgent());
    AttachmentData.put("topic",this.getTopic());
    AttachmentData.put("name",this.getName());
    AttachmentData.put("source",this.getSource());
    AttachmentData.put("payload",this.getPayload());
    try {
        AuthenticationSNowInfo auth = new AuthenticationSNowInfo(sysDomain);
        String UserId = auth.getUserId();
        String Password = auth.getpassword();

        if (this.webServiceAddress != null && !this.webServiceAddress.equalsIgnoreCase("")) {
            logger.debug("Calling webservice:  " + this.webServiceAddress);
            sNowLogger.debug("Calling webservice: " + this.webServiceAddress);
            url = new URL(this.webServiceAddress);
            conn = (HttpURLConnection) url.openConnection();
            String encoded = java.util.Base64.getEncoder()
                    .encodetoString((UserId + ":" + Password).getBytes(StandardCharsets.UTF_8));

            conn.setDoOutput(true);
            conn.setRequestMethod("POST");
            conn.setRequestProperty("Authorization","Basic " + encoded);
            conn.setRequestProperty("Content-Type","application/json");
            conn.setRequestProperty("Accept","application/json");
            OutputStream os = conn.getoutputStream();
            os.write(AttachmentData.toString().getBytes(StandardCharsets.UTF_8));
            os.flush();

            BufferedReader br;
            logger.debug(conn.getResponseCode());
            if (conn.getResponseCode() > 199 && conn.getResponseCode() < 300) {
                br = new BufferedReader(new InputStreamReader((conn.getInputStream()),StandardCharsets.UTF_8));
            } else {
                br = new BufferedReader(new InputStreamReader((conn.getErrorStream()),StandardCharsets.UTF_8));
            }
            returnjsON = br.readLine();

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...