簡體   English   中英

HTTP狀態代碼500是否表示未出現其余錯誤代碼

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

我正在嘗試使用HTTP PUT請求通過REST API更新對象。 我遇到了類似400的錯誤,但是現在修改代碼和標頭后,我得到了500,這意味着

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

這是否意味着以下我不必擔心的錯誤,這意味着該操作已被授權,方法未被禁止等,等等

  • 未經授權401
  • 必填402
  • 禁止403
  • 找不到404

ps我正在使用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"
}

刪除linbreaks並使用轉義序列后,我留下了用作我的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\" }

不幸的是,HTTP狀態500實際上只是服務器上意外錯誤的全部內容。 該錯誤可能在任何地方,即使在身份驗證代碼內也是如此。 因此,即使在發出401響應之前,該呼叫也可能會中斷。

在理想情況下,不會發生500個響應,因為開發人員會捕獲所有可能的錯誤並返回有用的響應。

服務所有者應該對500個錯誤感興趣,並關心它們,客戶端應該不會導致這些錯誤(確定的客戶端可以使用它們來對服務進行DOS)。 接下來最好的做法是與服務所有者聯系,並要求他們在日志中查找錯誤原因。

最終,由服務器決定要返回什么狀態碼,但是5xx狀態碼(與4xx狀態碼相反)的標准含義是服務器端發生了問題(例如服務器)執行無效的取消引用或其他嚴重錯誤),而4xx狀態代碼則表示正在發送的客戶端/請求有問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM