Builder method(String method, RequestBody body) { if (method == null) throw new NullPointerException("method == null"); if (method.length() == 0) throw new IllegalArgumentException("method.length() == 0"); if (body != null && !HttpMethod.permitsRequestBody(method)) { throw new IllegalArgumentException("method " + method + " must not have a request body."); } if (body == null && HttpMethod.requiresRequestBody(method)) { throw new IllegalArgumentException("method " + method + " must have a request body."); } this.method = method; if (body != null) { try { Buffer buffer = new Buffer(); body.writeTo(buffer); this.body = buffer.readByteArray(); MediaType contentType = body.contentType(); if (contentType != null) { addHeader(CONTENT_TYPE, contentType.toString()); } } catch (IOException e) { throw new RuntimeException(e); } } return this; }
Builder method(String method, RequestBody body) { if (method == null) throw new NullPointerException("method == null"); if (method.length() == 0) throw new IllegalArgumentException("method.length() == 0"); if (body != null && !HttpMethod.permitsRequestBody(method)) { throw new IllegalArgumentException("method " + method + " must not have a request body."); } if (body == null && HttpMethod.requiresRequestBody(method)) { throw new IllegalArgumentException("method " + method + " must have a request body."); } this.method = method; if (body != null) { try { Buffer buffer = new Buffer(); body.writeTo(buffer); this.body = buffer.readByteArray(); MediaType contentType = body.contentType(); if (contentType != null) { addHeader(CONTENT_TYPE, contentType.toString()); } } catch (IOException e) { throw new RuntimeException(e); } } return this; }