{"record":{"id":"2e7c06bc5db9da76","repo":"didi/DoKit","slug":"this-protocol-does-not-support-input","errorCode":null,"errorMessage":"This protocol does not support input","messagePattern":"This protocol does not support input","errorType":"exception","errorClass":"ProtocolException","httpStatus":null,"severity":"error","filePath":"Android/dokit/src/main/java/com/didichuxing/doraemonkit/aop/urlconnection/ObsoleteUrlFactory.java","lineNumber":455,"sourceCode":"            } catch (IOException e) {\n                return Collections.emptyMap();\n            }\n        }\n\n        @Override\n        public Map<String, List<String>> getRequestProperties() {\n            if (connected) {\n                throw new IllegalStateException(\n                        \"Cannot access request header fields after connection is set\");\n            }\n\n            return toMultimap(requestHeaders.build(), null);\n        }\n\n        @Override\n        public InputStream getInputStream() throws IOException {\n            if (!doInput) {\n                throw new ProtocolException(\"This protocol does not support input\");\n            }\n\n            Response response = getResponse(false);\n            if (response.code() >= HTTP_BAD_REQUEST) {\n                Log.e(\"DoKit\", \"FileNotFoundException:\" + url.toString());\n                return ConvertUtils.string2InputStream(\"FileNotFoundException:\" + url.toString(), \"utf-8\");\n            }\n\n            if (response.body() != null) {\n                return response.body().byteStream();\n            } else {\n                return ConvertUtils.string2InputStream(\"response.body() is null:\" + url.toString(), \"utf-8\");\n            }\n\n        }\n\n        @Override\n        public OutputStream getOutputStream() throws IOException {","sourceCodeStart":437,"sourceCodeEnd":473,"githubUrl":"https://github.com/didi/DoKit/blob/626827cddb2feb2f3aee87a52a064b4e5ca2bed4/Android/dokit/src/main/java/com/didichuxing/doraemonkit/aop/urlconnection/ObsoleteUrlFactory.java#L437-L473","documentation":"HttpURLConnection.getInputStream() honors the doInput flag; when doInput is false the wrapper throws ProtocolException(\"This protocol does not support input\") before attempting getResponse(). doInput defaults to true, so this only happens when setDoInput(false) was called explicitly (or setUseCaches/doInput state was misconfigured).","triggerScenarios":"Calling setDoInput(false) (e.g. for a pure upload) and then still calling getInputStream(); also getResponseCode()/getContent() after disabling input.","commonSituations":"Copy-pasted POST-upload snippets that call setDoOutput(true) plus setDoInput(false), followed by generic response-reading code that assumes getInputStream() always works.","solutions":["Do not call getInputStream() when you set setDoInput(false); remove one or the other.","Leave doInput at its default true when you need to read the response (even just the status line/error body).","If you only need the status code for an upload, call getResponseCode() with doInput left enabled."],"exampleFix":"// before\nconn.setDoOutput(true);\nconn.setDoInput(false);\n... write body ...\nInputStream is = conn.getInputStream(); // ProtocolException\n\n// after\nconn.setDoOutput(true); // doInput stays true by default\n... write body ...\nInputStream is = conn.getInputStream();","handlingStrategy":"validation","validationCode":"if (conn.getDoInput()) { readStream(conn.getInputStream()); } else { /* upload-only, skip read */ }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do not call setDoInput(false) unless the code path truly never reads the response.","Even for uploads, keep doInput true if you check the status code or error body."],"tags":["network","http","urlconnection","configuration"],"backgroundTag":null,"analyzedSha":"626827cddb2feb2f3aee87a52a064b4e5ca2bed4","analyzedAt":"2026-08-14T12:45:58.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}