{"record":{"id":"6c4df5d74ca87f6f","repo":"code4craft/webmagic","slug":"illegal-http-method","errorCode":null,"errorMessage":"Illegal HTTP Method ","messagePattern":"Illegal HTTP Method ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"webmagic-core/src/main/java/us/codecraft/webmagic/downloader/HttpUriRequestConverter.java","lineNumber":107,"sourceCode":"    }\n\n    private RequestBuilder selectRequestMethod(Request request) {\n        String method = request.getMethod();\n        if (method == null || method.equalsIgnoreCase(HttpConstant.Method.GET)) {\n            //default get\n            return RequestBuilder.get();\n        } else if (method.equalsIgnoreCase(HttpConstant.Method.POST)) {\n            return addFormParams(RequestBuilder.post(),request);\n        } else if (method.equalsIgnoreCase(HttpConstant.Method.HEAD)) {\n            return RequestBuilder.head();\n        } else if (method.equalsIgnoreCase(HttpConstant.Method.PUT)) {\n            return addFormParams(RequestBuilder.put(), request);\n        } else if (method.equalsIgnoreCase(HttpConstant.Method.DELETE)) {\n            return RequestBuilder.delete();\n        } else if (method.equalsIgnoreCase(HttpConstant.Method.TRACE)) {\n            return RequestBuilder.trace();\n        }\n        throw new IllegalArgumentException(\"Illegal HTTP Method \" + method);\n    }\n\n    private RequestBuilder addFormParams(RequestBuilder requestBuilder, Request request) {\n        if (request.getRequestBody() != null) {\n            ByteArrayEntity entity = new ByteArrayEntity(request.getRequestBody().getBody());\n            entity.setContentType(request.getRequestBody().getContentType());\n            requestBuilder.setEntity(entity);\n        }\n        return requestBuilder;\n    }\n\n}\n","sourceCodeStart":89,"sourceCodeEnd":120,"githubUrl":"https://github.com/code4craft/webmagic/blob/67816a19d68a4fec4657bf1336227e046e251df2/webmagic-core/src/main/java/us/codecraft/webmagic/downloader/HttpUriRequestConverter.java#L89-L120","documentation":"HttpUriRequestConverter.selectRequestMethod() maps a Request's method string to an Apache HttpClient RequestBuilder; if the method is not one of GET/POST/PUT/DELETE/HEAD/PATCH/OPTIONS/TRACE it throws IllegalArgumentException('Illegal HTTP Method ' + method).","triggerScenarios":"Building a Request with Request.create(method, ...) where method is misspelled ('gets', 'post ') or an unsupported verb (e.g. 'CONNECT'); passing a null/empty method string.","commonSituations":"Typing the HTTP verb by hand; copying a method name from another framework; dynamically deriving the method from an upstream value that includes unexpected verbs.","solutions":["Use HttpConstant.Method constants (Request.Method GET/POST/...) instead of raw strings","Trim/uppercase the method string before creating the Request","Only use methods in the supported set: GET, POST, PUT, DELETE, HEAD, PATCH, OPTIONS, TRACE"],"exampleFix":"// before\nRequest request = new Request(\"http://x\", \"gets\");\n// after\nRequest request = new Request(\"http://x\", HttpConstant.Method.GET);","handlingStrategy":"validation","validationCode":"java.util.Set<String> ok = Set.of(\"GET\",\"POST\",\"PUT\",\"DELETE\",\"HEAD\",\"PATCH\",\"OPTIONS\",\"TRACE\"); if (!ok.contains(method.trim().toUpperCase())) throw ...;","typeGuard":null,"tryCatchPattern":"try { spider.addRequest(request); } catch (IllegalArgumentException e) { /* fix method name */ }","preventionTips":["Use HttpConstant.Method constants instead of string literals","Normalize method strings (trim + toUpperCase)","Never derive method names from untrusted input"],"tags":["http","argument-validation","enum"],"backgroundTag":"invalid-enum-value","analyzedSha":"67816a19d68a4fec4657bf1336227e046e251df2","analyzedAt":"2026-09-08T11:15:28.425Z","contentChangedAt":"2026-09-08T11:15:28.425Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}