Skip to content

Instantly share code, notes, and snippets.

@ritou
Last active September 13, 2020 09:13
Show Gist options
  • Save ritou/452fa14af83e00fb8eb82496a4b1c505 to your computer and use it in GitHub Desktop.
Save ritou/452fa14af83e00fb8eb82496a4b1c505 to your computer and use it in GitHub Desktop.
iex(1)> Application.ensure_all_started(:hackney)
{:ok,
 [:unicode_util_compat, :idna, :mimerl, :certifi, :syntax_tools, :parse_trans,
  :ssl_verify_fun, :metrics, :hackney]}
  
iex(2)> :hackney.request(:get, "https://example.com", [], "", [:with_body])
{:ok, 200,
 [
   {"Accept-Ranges", "bytes"},
   {"Age", "248588"},
   {"Cache-Control", "max-age=604800"},
   {"Content-Type", "text/html; charset=UTF-8"},
   {"Date", "Sun, 13 Sep 2020 09:09:34 GMT"},
   {"Etag", "\"3147526947\""},
   {"Expires", "Sun, 20 Sep 2020 09:09:34 GMT"},
   {"Last-Modified", "Thu, 17 Oct 2019 07:18:26 GMT"},
   {"Server", "ECS (sjc/4E74)"},
   {"Vary", "Accept-Encoding"},
   {"X-Cache", "HIT"},
   {"Content-Length", "1256"}
 ],
 "<!doctype html>\n<html>\n<head>\n    <title>Example Domain</title>\n\n    <meta charset=\"utf-8\" />\n    <meta http-equiv=\"Content-type\" content=\"text/html; charset=utf-8\" />\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n    <style type=\"text/css\">\n    body {\n        background-color: #f0f0f2;\n        margin: 0;\n        padding: 0;\n        font-family: -apple-system, system-ui, BlinkMacSystemFont, \"Segoe UI\", \"Open Sans\", \"Helvetica Neue\", Helvetica, Arial, sans-serif;\n        \n    }\n    div {\n        width: 600px;\n        margin: 5em auto;\n        padding: 2em;\n        background-color: #fdfdff;\n        border-radius: 0.5em;\n        box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);\n    }\n    a:link, a:visited {\n        color: #38488f;\n        text-decoration: none;\n    }\n    @media (max-width: 700px) {\n        div {\n            margin: 0 auto;\n            width: auto;\n        }\n    }\n    </style>    \n</head>\n\n<body>\n<div>\n    <h1>Example Domain</h1>\n    <p>This domain is for use in illustrative examples in documents. You may use this\n    domain in literature without prior coordination or asking for permission.</p>\n    <p><a href=\"https://www.iana.org/domains/example\">More information...</a></p>\n</div>\n</body>\n</html>\n"}

# 
iex(3)> HTTPoison.get("https://example.com")
{:ok,
 %HTTPoison.Response{
   body: "<!doctype html>\n<html>\n<head>\n    <title>Example Domain</title>\n\n    <meta charset=\"utf-8\" />\n    <meta http-equiv=\"Content-type\" content=\"text/html; charset=utf-8\" />\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n    <style type=\"text/css\">\n    body {\n        background-color: #f0f0f2;\n        margin: 0;\n        padding: 0;\n        font-family: -apple-system, system-ui, BlinkMacSystemFont, \"Segoe UI\", \"Open Sans\", \"Helvetica Neue\", Helvetica, Arial, sans-serif;\n        \n    }\n    div {\n        width: 600px;\n        margin: 5em auto;\n        padding: 2em;\n        background-color: #fdfdff;\n        border-radius: 0.5em;\n        box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);\n    }\n    a:link, a:visited {\n        color: #38488f;\n        text-decoration: none;\n    }\n    @media (max-width: 700px) {\n        div {\n            margin: 0 auto;\n            width: auto;\n        }\n    }\n    </style>    \n</head>\n\n<body>\n<div>\n    <h1>Example Domain</h1>\n    <p>This domain is for use in illustrative examples in documents. You may use this\n    domain in literature without prior coordination or asking for permission.</p>\n    <p><a href=\"https://www.iana.org/domains/example\">More information...</a></p>\n</div>\n</body>\n</html>\n",
   headers: [
     {"Age", "178094"},
     {"Cache-Control", "max-age=604800"},
     {"Content-Type", "text/html; charset=UTF-8"},
     {"Date", "Sun, 13 Sep 2020 09:11:59 GMT"},
     {"Etag", "\"3147526947+ident\""},
     {"Expires", "Sun, 20 Sep 2020 09:11:59 GMT"},
     {"Last-Modified", "Thu, 17 Oct 2019 07:18:26 GMT"},
     {"Server", "ECS (sjc/16DF)"},
     {"Vary", "Accept-Encoding"},
     {"X-Cache", "HIT"},
     {"Content-Length", "1256"}
   ],
   request: %HTTPoison.Request{
     body: "",
     headers: [],
     method: :get,
     options: [],
     params: %{},
     url: "https://example.com"
   },
   request_url: "https://example.com",
   status_code: 200
 }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment