Sends an HTTP request and returns the response. @param href URL to send the request to (can be empty string) @param request request data @param bodies request body @return HTTP response @throws QueryException query exception
(final byte[] href, final XNode request, final Value bodies)
| 62 | * @throws QueryException query exception |
| 63 | */ |
| 64 | public Value sendRequest(final byte[] href, final XNode request, final Value bodies) |
| 65 | throws QueryException { |
| 66 | |
| 67 | final Request req = new RequestParser(info).parse(request, bodies); |
| 68 | final URI uri = uri(href, req); |
| 69 | final String mediaType = req.attribute(OVERRIDE_MEDIA_TYPE); |
| 70 | final String status = req.attribute(STATUS_ONLY); |
| 71 | final boolean body = status == null || Strings.isFalse(status); |
| 72 | |
| 73 | final MainOptions mopts = new MainOptions(options); |
| 74 | try { |
| 75 | mopts.set(MainOptions.CSVPARSER, |
| 76 | assign(new CsvParserOptions(mopts.get(MainOptions.CSVPARSER)), req.attribute(CSV))); |
| 77 | mopts.set(MainOptions.JSONPARSER, |
| 78 | assign(new JsonParserOptions(mopts.get(MainOptions.JSONPARSER)), req.attribute(JSON))); |
| 79 | mopts.set(MainOptions.HTMLPARSER, |
| 80 | assign(new HtmlOptions(mopts.get(MainOptions.HTMLPARSER)), req.attribute(HTML))); |
| 81 | |
| 82 | return new Response(info, mopts).getResponse(send(uri, req), body, mediaType); |
| 83 | } catch(final IOException ex) { |
| 84 | throw HC_ERROR_X.get(info, ex); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Assigns parser options. |