简体   繁体   English

HTTP状态代码500是否表示未出现其余错误代码

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

I am trying to update an object via REST API with an HTTP PUT request. 我正在尝试使用HTTP PUT请求通过REST API更新对象。 I was getting different errors like 400 but now after amending my code and headers I am getting 500 which means that 我遇到了类似400的错误,但是现在修改代码和标头后,我得到了500,这意味着

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

Does this mean the following errors I don't have to worry about, meaning the operation is authorized, method is not forbidden etc etc 这是否意味着以下我不必担心的错误,这意味着该操作已被授权,方法未被禁止等,等等

  • Unauthorized 401 未经授权401
  • PaymentRequired 402 必填402
  • Forbidden 403 禁止403
  • Not found 404 找不到404

ps I am using JSON. 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();

My original JSON is following 我的原始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"
}

after removing linbreaks and using escape sequence, I am left with the follwowing string which I am using as my JSON 删除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\" }

Unfortunately, HTTP status 500 is really just a catch-all for unexpected errors on the server. 不幸的是,HTTP状态500实际上只是服务器上意外错误的全部内容。 The error could be anywhere, even within the authentication code. 该错误可能在任何地方,即使在身份验证代码内也是如此。 So it's possible that the call is blowing up even before it would have issued a 401 response. 因此,即使在发出401响应之前,该呼叫也可能会中断。

In a perfect world, 500 responses wouldn't happen because developers would catch all possible errors and return useful responses instead. 在理想情况下,不会发生500个响应,因为开发人员会捕获所有可能的错误并返回有用的响应。

A service owner should be interested in and concerned about 500 errors, a client shouldn't be able to cause them (a determined client could use them to DOS the service). 服务所有者应该对500个错误感兴趣,并关心它们,客户端应该不会导致这些错误(确定的客户端可以使用它们来对服务进行DOS)。 The best thing to do next is to contact the service owner and ask them to look in their logs for the cause of the error. 接下来最好的做法是与服务所有者联系,并要求他们在日志中查找错误原因。

最终,由服务器决定要返回什么状态码,但是5xx状态码(与4xx状态码相反)的标准含义是服务器端发生了问题(例如服务器)执行无效的取消引用或其他严重错误),而4xx状态代码则表示正在发送的客户端/请求有问题。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM