HTTP 状态代码 500 是否意味着未发生其余错误代码

Does HTTP Status Code 500 means that the rest error code are not occuring

我正在尝试使用 HTTP PUT 请求通过 REST API 更新 object。我收到了 400 等不同的错误,但现在在修改我的代码后 headers 我收到了 500,这意味着

 Internal Error 500 : The server encountered an unexpected 
 condition which prevented it from fulfilling the request. 

这是否意味着我不必担心以下错误,意味着操作已被授权,方法未被禁止等等

p.s 我正在使用 JSON.

String json = "my json string with escape characters"
String st= "username:password";
byte[] encoded = Base64.encodeBase64(st.getBytes());           
String credentials = new String(encoded);
String url= "http://localhost:10108/grc/api/contents/20081";

URL object=new URL(url);
HttpURLConnection con = (HttpURLConnection) object.openConnection();

con.setDoOutput(true);
con.setDoInput(true);
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Accept","application/json");
con.setRequestProperty  ("Authorization", "Basic " + credentials);  

con.setRequestMethod("PUT");

JSONObject jsonObject = (JSONObject)new JSONParser().parse(json);

OutputStream os = con.getOutputStream();
os.write(jsonObject.toJSONString().getBytes());
os.flush();

int responseCode = con.getResponseCode();

我的原创JSON在关注

{
    "name": "Decommisioned CBU One",
    "id": "2116",   
    "description": "Decommisioned CBU One",
    "parentFolderId": "2115",
    "fields": {
        "field": [{
            "dataType": "ID_TYPE",
            "id": "29",
            "name": "Resource ID",
            "value": "2116"
        }, {
            "dataType": "STRING_TYPE",
            "id": "63",
            "name": "Comment"
        }, {
            "dataType": "INTEGER_TYPE",
            "id": "60",
            "name": "Created By",
            "value": 6
        }, {
            "dataType": "DATE_TYPE",
            "id": "59",
            "name": "Creation Date",
            "value": "2015-02-04T20:23:26.000+05:00"
        }, {
            "dataType": "STRING_TYPE",
            "id": "57",
            "name": "Description",
            "value": "Decommisioned CBU One"
        }, {
            "dataType": "DATE_TYPE",
            "id": "61",
            "name": "Last Modification Date",
            "value": "2015-02-04T20:23:26.000+05:00"
        }, {
            "dataType": "INTEGER_TYPE",
            "id": "62",
            "name": "Last Modified By",
            "value": 6
        }, {
            "dataType": "STRING_TYPE",
            "id": "58",
            "name": "Location",
            "value": "/_op_sox/Project/Default/BusinessEntity/Emirates NBD PJSC/Emirates NBD Bank/Wholesale Banking/(Decommissioned) Corporate Banking/Decommisioned CBU One/Decommisioned CBU One.txt"
        }, {
            "dataType": "STRING_TYPE",
            "id": "56",
            "name": "Name",
            "value": "Decommisioned CBU One.txt"
        }, {
            "dataType": "STRING_TYPE",
            "id": "66",
            "name": "Orphan"
        }, {
            "dataType": "STRING_TYPE",
            "id": "125",
            "name": "OPSS-BusEnt:Business Entity Chart",
            "value": "${\"labelKey\" : \"label.hierarchyDiagram.url\",   \"path\" : \"/visualization/VizRenderer.jsp\",   \"modes\" : [\"view\", \"edit\"],\n     \"parameters\" :{\"oid\" : \"$objectId\",\"viz\" : \"EntityHierarchy\"},\n     \"popUp\" : {       \"windowAttributes\" : \"height=800,width=1000,menubar=no,status=no,toolbar=no,scrollbars=yes,resizable=yes,name=_blank\"\n     }\n     }"
        }, {
            "dataType": "STRING_TYPE",
            "id": "124",
            "name": "OPSS-BusEnt:Compliance Owner"
        }, {
            "dataType": "ENUM_TYPE",
            "id": "121",
            "name": "OPSS-BusEnt:Entity Type",
            "enumValue": {
                "id": "229",
                "name": "Business",
                "localizedLabel": "Business",
                "index": 2,
                "hidden": false
            }
        }, {
            "dataType": "STRING_TYPE",
            "id": "123",
            "name": "OPSS-BusEnt:Executive Owner"
        }, {
            "dataType": "ENUM_TYPE",
            "id": "133",
            "name": "OPSS-BusEnt:In RCSA Scope",
            "enumValue": {
                "id": "227",
                "name": "No",
                "localizedLabel": "No",
                "index": 2,
                "hidden": false
            }
        }, {
            "dataType": "MULTI_VALUE_ENUM",
            "id": "122",
            "name": "OPSS-BusEnt:In Scope"
        }, {
            "dataType": "STRING_TYPE",
            "id": "126",
            "name": "OPSS-BusEnt:Logo URL"
        }, {
            "dataType": "CURRENCY_TYPE",
            "id": "132",
            "name": "OPSS-BusEnt:Risk Appetite",
            "baseAmount": 0.0,
            "localAmount": 0.0
        }]
    },
    "typeDefinitionId": "6",
    "primaryParentId": "2112"
}

删除换行符并使用转义序列后,我剩下下面的字符串,我将其用作 JSON

{ \"name\": \"Decommisioned CBU One\", \"id\": \"2116\", \"description\": \"Decommisioned CBU One\", \"parentFolderId\": \"2115\", \"fields\": { \"field\": [{ \"dataType\": \"ID_TYPE\", \"id\": \"29\", \"name\": \"Resource ID\", \"value\": \"2116\" }, { \"dataType\": \"STRING_TYPE\", \"id\": \"63\", \"name\": \"Comment\" }, { \"dataType\": \"INTEGER_TYPE\", \"id\": \"60\", \"name\": \"Created By\", \"value\": 6 }, { \"dataType\": \"DATE_TYPE\", \"id\": \"59\", \"name\": \"Creation Date\", \"value\": \"2015-02-04T20:23:26.000+05:00\" }, { \"dataType\": \"STRING_TYPE\", \"id\": \"57\", \"name\": \"Description\", \"value\": \"Decommisioned CBU One\" }, { \"dataType\": \"DATE_TYPE\", \"id\": \"61\", \"name\": \"Last Modification Date\", \"value\": \"2015-02-04T20:23:26.000+05:00\" }, { \"dataType\": \"INTEGER_TYPE\", \"id\": \"62\", \"name\": \"Last Modified By\", \"value\": 6 }, { \"dataType\": \"STRING_TYPE\", \"id\": \"58\", \"name\": \"Location\", \"value\": \"/_op_sox/Project/Default/BusinessEntity/Emirates NBD PJSC/Emirates NBD Bank/Wholesale Banking/(Decommissioned) Corporate Banking/Decommisioned CBU One/Decommisioned CBU One.txt\" }, { \"dataType\": \"STRING_TYPE\", \"id\": \"56\", \"name\": \"Name\", \"value\": \"Decommisioned CBU One.txt\" }, { \"dataType\": \"STRING_TYPE\", \"id\": \"66\", \"name\": \"Orphan\" }, { \"dataType\": \"STRING_TYPE\", \"id\": \"125\", \"name\": \"OPSS-BusEnt:Business Entity Chart\", \"value\": \"${\"labelKey\" : \"label.hierarchyDiagram.url\", \"path\" : \"/visualization/VizRenderer.jsp\", \"modes\" : [\"view\", \"edit\"],\n \"parameters\" :{\"oid\" : \"$objectId\",\"viz\" : \"EntityHierarchy\"},\n \"popUp\" : { \"windowAttributes\" : \"height=800,width=1000,menubar=no,status=no,toolbar=no,scrollbars=yes,resizable=yes,name=_blank\"\n }\n }\" }, { \"dataType\": \"STRING_TYPE\", \"id\": \"124\", \"name\": \"OPSS-BusEnt:Compliance Owner\" }, { \"dataType\": \"ENUM_TYPE\", \"id\": \"121\", \"name\": \"OPSS-BusEnt:Entity Type\", \"enumValue\": { \"id\": \"229\", \"name\": \"Business\", \"localizedLabel\": \"Business\", \"index\": 2, \"hidden\": false } }, { \"dataType\": \"STRING_TYPE\", \"id\": \"123\", \"name\": \"OPSS-BusEnt:Executive Owner\" }, { \"dataType\": \"ENUM_TYPE\", \"id\": \"133\", \"name\": \"OPSS-BusEnt:In RCSA Scope\", \"enumValue\": { \"id\": \"227\", \"name\": \"No\", \"localizedLabel\": \"No\", \"index\": 2, \"hidden\": false } }, { \"dataType\": \"MULTI_VALUE_ENUM\", \"id\": \"122\", \"name\": \"OPSS-BusEnt:In Scope\" }, { \"dataType\": \"STRING_TYPE\", \"id\": \"126\", \"name\": \"OPSS-BusEnt:Logo URL\" }, { \"dataType\": \"CURRENCY_TYPE\", \"id\": \"132\", \"name\": \"OPSS-BusEnt:Risk Appetite\", \"baseAmount\": 0.0, \"localAmount\": 0.0 }] }, \"typeDefinitionId\": \"6\", \"primaryParentId\": \"2112\" }

最终,由服务器决定 return 的状态代码,但是 5xx 状态代码(相对于 4xx 状态代码)的标准含义是服务器端的事情(比如服务器执行空引用或其他一些严重错误),而 4xx 状态代码意味着发送的客户端/请求有问题。

不幸的是,HTTP 状态 500 实际上只是服务器上意外错误的一个包罗万象。错误可能在任何地方,甚至在身份验证代码中。因此,有可能呼叫甚至在发出 401 响应之前就中断了。

在理想情况下,不会出现 500 个响应,因为开发人员会捕获所有可能的错误并 return 有用的响应。

服务所有者应该对 500 错误感兴趣并关心,客户端不应该导致它们(确定的客户端可以使用它们来 DOS 服务)。接下来最好的办法是联系服务所有者,让他们在日志中查找错误原因。