{
  "doc": {
    "id": "api/commands/request",
    "title": "request | Cypress Documentation",
    "description": "Make an HTTP request in Cypress.",
    "section": "api",
    "source_path": "/llm/markdown/api/commands/request.md",
    "version": "e6988a974973e9090ce70406c38cb2b9e0eac9fa",
    "updated_at": "2026-05-15T15:50:22.536Z",
    "headings": [
      {
        "id": "api/commands/request#request",
        "text": "request",
        "level": 1
      },
      {
        "id": "api/commands/request#syntax",
        "text": "Syntax",
        "level": 2
      },
      {
        "id": "api/commands/request#usage",
        "text": "Usage",
        "level": 3
      },
      {
        "id": "api/commands/request#arguments",
        "text": "Arguments",
        "level": 3
      },
      {
        "id": "api/commands/request#yields-learn-about-subject-management",
        "text": "Yields Learn about subject management",
        "level": 3
      },
      {
        "id": "api/commands/request#examples",
        "text": "Examples",
        "level": 2
      },
      {
        "id": "api/commands/request#url",
        "text": "URL",
        "level": 3
      },
      {
        "id": "api/commands/request#make-a-get-request",
        "text": "Make a GET request",
        "level": 4
      },
      {
        "id": "api/commands/request#issue-an-http-request",
        "text": "Issue an HTTP request",
        "level": 4
      },
      {
        "id": "api/commands/request#method-and-url",
        "text": "Method and URL",
        "level": 3
      },
      {
        "id": "api/commands/request#send-a-delete-request",
        "text": "Send a DELETE request",
        "level": 4
      },
      {
        "id": "api/commands/request#alias-the-request-using-as",
        "text": "Alias the request using .as()",
        "level": 4
      },
      {
        "id": "api/commands/request#method-url-and-body",
        "text": "Method, URL, and Body",
        "level": 3
      },
      {
        "id": "api/commands/request#send-a-post-request-with-a-json-body",
        "text": "Send a POST request with a JSON body",
        "level": 4
      },
      {
        "id": "api/commands/request#options",
        "text": "Options",
        "level": 3
      },
      {
        "id": "api/commands/request#request-a-page-while-disabling-auto-redirect",
        "text": "Request a page while disabling auto redirect",
        "level": 4
      },
      {
        "id": "api/commands/request#download-a-pdf-file",
        "text": "Download a PDF file",
        "level": 4
      },
      {
        "id": "api/commands/request#get-data-url-of-an-image",
        "text": "Get Data URL of an image",
        "level": 4
      },
      {
        "id": "api/commands/request#html-form-submissions-using-form-option",
        "text": "HTML form submissions using form option",
        "level": 4
      },
      {
        "id": "api/commands/request#using-cy-request-for-html-forms",
        "text": "Using cy.request() for HTML Forms",
        "level": 4
      },
      {
        "id": "api/commands/request#request-polling",
        "text": "Request Polling",
        "level": 3
      },
      {
        "id": "api/commands/request#call-cy-request-over-and-over-again",
        "text": "Call cy.request() over and over again",
        "level": 4
      },
      {
        "id": "api/commands/request#notes",
        "text": "Notes",
        "level": 2
      },
      {
        "id": "api/commands/request#debugging",
        "text": "Debugging",
        "level": 3
      },
      {
        "id": "api/commands/request#request-is-not-displayed-in-the-network-tab-of-developer-tools",
        "text": "Request is not displayed in the Network Tab of Developer Tools",
        "level": 4
      },
      {
        "id": "api/commands/request#cors",
        "text": "CORS",
        "level": 3
      },
      {
        "id": "api/commands/request#cors-is-bypassed",
        "text": "CORS is bypassed",
        "level": 4
      },
      {
        "id": "api/commands/request#cookies",
        "text": "Cookies",
        "level": 3
      },
      {
        "id": "api/commands/request#cookies-are-automatically-sent-and-received",
        "text": "Cookies are automatically sent and received",
        "level": 4
      },
      {
        "id": "api/commands/request#cy-intercept",
        "text": "cy.intercept()",
        "level": 3
      },
      {
        "id": "api/commands/request#cy-request-sends-requests-to-actual-endpoints-bypassing-those-defined-using-cy-intercept",
        "text": "cy.request() sends requests to actual endpoints, bypassing those defined using cy.intercept()",
        "level": 4
      },
      {
        "id": "api/commands/request#user-agent",
        "text": "User agent",
        "level": 3
      },
      {
        "id": "api/commands/request#rules",
        "text": "Rules",
        "level": 2
      },
      {
        "id": "api/commands/request#requirements-learn-about-chaining-commands",
        "text": "Requirements Learn about chaining commands",
        "level": 3
      },
      {
        "id": "api/commands/request#assertions-learn-about-assertions",
        "text": "Assertions Learn about assertions",
        "level": 3
      },
      {
        "id": "api/commands/request#timeouts-learn-about-timeouts",
        "text": "Timeouts Learn about timeouts",
        "level": 3
      },
      {
        "id": "api/commands/request#command-log",
        "text": "Command Log",
        "level": 2
      },
      {
        "id": "api/commands/request#history",
        "text": "History",
        "level": 2
      },
      {
        "id": "api/commands/request#see-also",
        "text": "See also",
        "level": 2
      }
    ]
  },
  "chunks": [
    {
      "id": "api/commands/request#syntax",
      "doc_id": "api/commands/request",
      "heading": "Syntax",
      "heading_level": 2,
      "content_markdown": "## Syntax\n\n```\ncy.request(url)cy.request(url, body)cy.request(method, url)cy.request(method, url, body)cy.request(options)\n```\n\n### Usage\n\n**Correct Usage**\n\n```\ncy.request('http://dev.local/seed')\n```\n\n### Arguments\n\n**url _(String)_**\n\nThe URL to make the request to.\n\nIf you do not provide a fully qualified domain name (FQDN) URL, Cypress will make its best guess as to which host you want `cy.request()` to use in the URL.\n\n1.  If you make a `cy.request()` after visiting a page, Cypress assumes the URL used for the `cy.visit()` is the host.\n\n```\ncy.visit('http://localhost:8080/app')cy.request('users/1.json') //  URL is  http://localhost:8080/users/1.json\n```\n\n1.  If you make a `cy.request()` prior to visiting a page, Cypress assumes the host is the `baseUrl` property configured inside of of your [configuration file](/llm/markdown/app/references/configuration.md).\n\n*   cypress.config.js\n*   cypress.config.ts\n\n```\nconst { defineConfig } = require('cypress')module.exports = defineConfig({  e2e: {    baseUrl: 'http://localhost:1234',  },})\n```\n\n```\nimport { defineConfig } from 'cypress'export default defineConfig({  e2e: {    baseUrl: 'http://localhost:1234',  },})\n```\n\n```\ncy.request('seed/admin') // URL is http://localhost:1234/seed/admin\n```\n\n1.  If Cypress cannot determine the host it will throw an error.\n\n**body _(String, Object)_**\n\nA request `body` to be sent in the request. Cypress sets the `Accepts` request header and serializes the response body by the `encoding` option.\n\n**method _(String)_**\n\nMake a request using a specific method. If no method is defined, Cypress uses the `GET` method by default.\n\nSupported methods include:\n\n*   `GET`\n*   `POST`\n*   `PUT`\n*   `DELETE`\n*   `PATCH`\n*   `HEAD`\n*   `OPTIONS`\n*   `TRACE`\n*   `COPY`\n*   `LOCK`\n*   `MKCOL`\n*   `MOVE`\n*   `PURGE`\n*   `PROPFIND`\n*   `PROPPATCH`\n*   `UNLOCK`\n*   `REPORT`\n*   `MKACTIVITY`\n*   `CHECKOUT`\n*   `MERGE`\n*   `M-SEARCH`\n*   `NOTIFY`\n*   `SUBSCRIBE`\n*   `UNSUBSCRIBE`\n*   `SEARCH`\n*   `CONNECT`\n\n**options _(Object)_**\n\nPass in an options object to change the default behavior of `cy.request()`.\n\nYou can also set options for `cy.request()`'s `baseUrl` and `responseTimeout` globally in [configuration](/llm/markdown/app/references/configuration.md).\n\n| Option | Default | Description |\n| --- | --- | --- |\n| `log` | `true` | Displays the command in the [Command log](/llm/markdown/app/core-concepts/open-mode.md#Command-Log) |\n| `url` | `null` | The URL to make the request to |\n| `method` | `GET` | The HTTP method to use in the request |\n| `auth` | `null` | Adds Authorization headers. [Accepts these options.](https://github.com/request/request#http-authentication) |\n| `body` | `null` | Body to send along with the request |\n| `failOnStatusCode` | `true` | Whether to fail on response codes other than `2xx` and `3xx` |\n| `followRedirect` | `true` | Whether to automatically follow redirects |\n| `form` | `false` | Whether to convert the `body` values to URL encoded content and set the `x-www-form-urlencoded` header |\n| `encoding` | `utf8` | The encoding to be used when serializing the response body. The following encodings are supported: `ascii`, `base64`, `binary`, `hex`, `latin1`, `utf8`, `utf-8`, `ucs2`, `ucs-2`, `utf16le`, `utf-16le` |\n| `gzip` | `true` | Whether to accept the `gzip` encoding |\n| `headers` | `null` | Additional headers to send; Accepts object literal. _Note:_ `headers` will only be sent for the initial request for `cy.request()`, not for any subsequent requests. |\n| `qs` | `null` | Query parameters to append to the `url` of the request |\n| `retryOnStatusCodeFailure` | `false` | Whether Cypress should automatically retry status code errors under the hood. Cypress will retry a request up to 4 times if this is set to true. |\n| `retryOnNetworkFailure` | `true` | Whether Cypress should automatically retry transient network errors under the hood. Cypress will retry a request up to 4 times if this is set to true. |\n| `timeout` | [`responseTimeout`](/llm/markdown/app/references/configuration.md#Timeouts) | Time to wait for `cy.request()` to resolve before [timing out](#Timeouts) |\n\nYou can also set options for `cy.request()`'s `baseUrl` and `responseTimeout` globally in the [Cypress configuration](/llm/markdown/app/references/configuration.md).\n\n### Yields [Learn about subject management](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Subject-Management)\n\n`cy.request()` yields the `response` as an object literal containing properties such as:\n\n*   `status`\n*   `body`\n*   `headers`\n*   `duration`\n",
      "section": "api",
      "anchors": [
        "syntax"
      ],
      "path": "/llm/json/chunked/api/commands/request.json",
      "token_estimate": 844
    },
    {
      "id": "api/commands/request#arguments",
      "doc_id": "api/commands/request",
      "heading": "Arguments",
      "heading_level": 3,
      "content_markdown": "### Arguments\n\n**url _(String)_**\n\nThe URL to make the request to.\n\nIf you do not provide a fully qualified domain name (FQDN) URL, Cypress will make its best guess as to which host you want `cy.request()` to use in the URL.\n\n1.  If you make a `cy.request()` after visiting a page, Cypress assumes the URL used for the `cy.visit()` is the host.\n\n```\ncy.visit('http://localhost:8080/app')cy.request('users/1.json') //  URL is  http://localhost:8080/users/1.json\n```\n\n1.  If you make a `cy.request()` prior to visiting a page, Cypress assumes the host is the `baseUrl` property configured inside of of your [configuration file](/llm/markdown/app/references/configuration.md).\n\n*   cypress.config.js\n*   cypress.config.ts\n\n```\nconst { defineConfig } = require('cypress')module.exports = defineConfig({  e2e: {    baseUrl: 'http://localhost:1234',  },})\n```\n\n```\nimport { defineConfig } from 'cypress'export default defineConfig({  e2e: {    baseUrl: 'http://localhost:1234',  },})\n```\n\n```\ncy.request('seed/admin') // URL is http://localhost:1234/seed/admin\n```\n\n1.  If Cypress cannot determine the host it will throw an error.\n\n**body _(String, Object)_**\n\nA request `body` to be sent in the request. Cypress sets the `Accepts` request header and serializes the response body by the `encoding` option.\n\n**method _(String)_**\n\nMake a request using a specific method. If no method is defined, Cypress uses the `GET` method by default.\n\nSupported methods include:\n\n*   `GET`\n*   `POST`\n*   `PUT`\n*   `DELETE`\n*   `PATCH`\n*   `HEAD`\n*   `OPTIONS`\n*   `TRACE`\n*   `COPY`\n*   `LOCK`\n*   `MKCOL`\n*   `MOVE`\n*   `PURGE`\n*   `PROPFIND`\n*   `PROPPATCH`\n*   `UNLOCK`\n*   `REPORT`\n*   `MKACTIVITY`\n*   `CHECKOUT`\n*   `MERGE`\n*   `M-SEARCH`\n*   `NOTIFY`\n*   `SUBSCRIBE`\n*   `UNSUBSCRIBE`\n*   `SEARCH`\n*   `CONNECT`\n\n**options _(Object)_**\n\nPass in an options object to change the default behavior of `cy.request()`.\n\nYou can also set options for `cy.request()`'s `baseUrl` and `responseTimeout` globally in [configuration](/llm/markdown/app/references/configuration.md).\n\n| Option | Default | Description |\n| --- | --- | --- |\n| `log` | `true` | Displays the command in the [Command log](/llm/markdown/app/core-concepts/open-mode.md#Command-Log) |\n| `url` | `null` | The URL to make the request to |\n| `method` | `GET` | The HTTP method to use in the request |\n| `auth` | `null` | Adds Authorization headers. [Accepts these options.](https://github.com/request/request#http-authentication) |\n| `body` | `null` | Body to send along with the request |\n| `failOnStatusCode` | `true` | Whether to fail on response codes other than `2xx` and `3xx` |\n| `followRedirect` | `true` | Whether to automatically follow redirects |\n| `form` | `false` | Whether to convert the `body` values to URL encoded content and set the `x-www-form-urlencoded` header |\n| `encoding` | `utf8` | The encoding to be used when serializing the response body. The following encodings are supported: `ascii`, `base64`, `binary`, `hex`, `latin1`, `utf8`, `utf-8`, `ucs2`, `ucs-2`, `utf16le`, `utf-16le` |\n| `gzip` | `true` | Whether to accept the `gzip` encoding |\n| `headers` | `null` | Additional headers to send; Accepts object literal. _Note:_ `headers` will only be sent for the initial request for `cy.request()`, not for any subsequent requests. |\n| `qs` | `null` | Query parameters to append to the `url` of the request |\n| `retryOnStatusCodeFailure` | `false` | Whether Cypress should automatically retry status code errors under the hood. Cypress will retry a request up to 4 times if this is set to true. |\n| `retryOnNetworkFailure` | `true` | Whether Cypress should automatically retry transient network errors under the hood. Cypress will retry a request up to 4 times if this is set to true. |\n| `timeout` | [`responseTimeout`](/llm/markdown/app/references/configuration.md#Timeouts) | Time to wait for `cy.request()` to resolve before [timing out](#Timeouts) |\n\nYou can also set options for `cy.request()`'s `baseUrl` and `responseTimeout` globally in the [Cypress configuration](/llm/markdown/app/references/configuration.md).\n",
      "section": "api",
      "anchors": [
        "arguments"
      ],
      "path": "/llm/json/chunked/api/commands/request.json",
      "token_estimate": 788
    },
    {
      "id": "api/commands/request#examples",
      "doc_id": "api/commands/request",
      "heading": "Examples",
      "heading_level": 2,
      "content_markdown": "## Examples\n\n### URL\n\n#### Make a `GET` request\n\n`cy.request()` is great for talking to an external endpoint before your tests to seed a database.\n\n```\nbeforeEach(() => {  cy.request('http://localhost:8080/db/seed')})\n```\n\n#### Issue an HTTP request\n\nSometimes it's quicker to test the contents of a page rather than [`cy.visit()`](/llm/markdown/api/commands/visit.md) and wait for the entire page and all of its resources to load.\n\n```\ncy.request('/admin').its('body').should('include', '<h1>Admin</h1>')\n```\n\n### Method and URL\n\n#### Send a `DELETE` request\n\n```\ncy.request('DELETE', 'http://localhost:8888/users/827')\n```\n\n#### Alias the request using [.as()](/llm/markdown/api/commands/as.md)\n\n```\ncy.request('https://jsonplaceholder.cypress.io/comments').as('comments')cy.get('@comments').should((response) => {  expect(response.body).to.have.length(500)  expect(response).to.have.property('headers')  expect(response).to.have.property('duration')})\n```\n\n### Method, URL, and Body\n\n#### Send a `POST` request with a JSON body\n\n```\ncy.request('POST', 'http://localhost:8888/users/admin', { name: 'Jane' }).then(  (response) => {    // response.body is automatically serialized into JSON    expect(response.body).to.have.property('name', 'Jane') // true  })\n```\n\n### Options\n\n#### Request a page while disabling auto redirect\n\nTo test the redirection behavior of a login without a session, `cy.request` can be used to check the `status` and `redirectedToUrl` property.\n\nThe `redirectedToUrl` property is a special Cypress property that normalizes the URL the browser would normally follow during a redirect.\n\n```\ncy.request({  url: '/dashboard',  followRedirect: false, // turn off following redirects}).then((resp) => {  // redirect status code is 302  expect(resp.status).to.eq(302)  expect(resp.redirectedToUrl).to.eq('http://localhost:8082/unauthorized')})\n```\n\n#### Download a PDF file\n\nBy passing the `encoding: binary` option, the `response.body` will be serialized binary content of the file. You can use this to access various file types via `.request()` like `.pdf`, `.zip`, or `.doc` files.\n\n```\ncy.request({  url: 'http://localhost:8080/some-document.pdf',  encoding: 'binary',}).then((response) => {  cy.writeFile('path/to/save/document.pdf', response.body, 'binary')})\n```\n\n#### Get Data URL of an image\n\nBy passing the `encoding: base64` option, the `response.body` will be base64-encoded content of the image. You can use this to construct a [Data URI](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs) for use elsewhere.\n\n```\ncy.request({  url: 'https://docs.cypress.io/img/logo.png',  encoding: 'base64',}).then((response) => {  const base64Content = response.body  const mime = response.headers['content-type'] // or 'image/png'  // see https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs  const imageDataUrl = `data:${mime};base64,${base64Content}`})\n```\n\n#### HTML form submissions using form option\n\nOftentimes, once you have a proper e2e test around logging in, there's no reason to continue to `cy.visit()` the login and wait for the entire page to load all associated resources before running any other commands. Doing so can slow down our entire test suite.\n\nUsing `cy.request()`, we can bypass all of this because it automatically gets and sets cookies as if the requests had come from the browser.\n\n```\ncy.request({  method: 'POST',  url: '/login_with_form', // baseUrl is prepend to URL  form: true, // indicates the body should be form urlencoded and sets Content-Type: application/x-www-form-urlencoded headers  body: {    username: 'jane.lane',    password: 'password123',  },})// to prove we have a sessioncy.getCookie('cypress-session-cookie').should('exist')\n```\n\n#### Using `cy.request()` for HTML Forms\n\n[Check out our example recipe using `cy.request()` for HTML web forms](/llm/markdown/app/references/recipes.md#Logging-In)\n\n### Request Polling\n\n#### Call `cy.request()` over and over again\n\nThis is useful when you're polling a server for a response that may take awhile to complete.\n\nAll we're really doing here is creating a recursive function. Nothing more complicated than that.\n\n```\n// a regular ol' function folksfunction req () {  cy    .request(...)    .then((resp) => {      // if we got what we wanted      if (resp.status === 200 && resp.body.ok === true)        // break out of the recursive loop        return      // else recurse      req()    })}cy  // do the thing causing the side effect  .get('button').click()  // now start the requests  .then(req)\n```\n",
      "section": "api",
      "anchors": [
        "examples"
      ],
      "path": "/llm/json/chunked/api/commands/request.json",
      "token_estimate": 733
    },
    {
      "id": "api/commands/request#url",
      "doc_id": "api/commands/request",
      "heading": "URL",
      "heading_level": 3,
      "content_markdown": "### URL\n\n#### Make a `GET` request\n\n`cy.request()` is great for talking to an external endpoint before your tests to seed a database.\n\n```\nbeforeEach(() => {  cy.request('http://localhost:8080/db/seed')})\n```\n\n#### Issue an HTTP request\n\nSometimes it's quicker to test the contents of a page rather than [`cy.visit()`](/llm/markdown/api/commands/visit.md) and wait for the entire page and all of its resources to load.\n\n```\ncy.request('/admin').its('body').should('include', '<h1>Admin</h1>')\n```\n",
      "section": "api",
      "anchors": [
        "url"
      ],
      "path": "/llm/json/chunked/api/commands/request.json",
      "token_estimate": 85
    },
    {
      "id": "api/commands/request#issue-an-http-request",
      "doc_id": "api/commands/request",
      "heading": "Issue an HTTP request",
      "heading_level": 4,
      "content_markdown": "#### Issue an HTTP request\n\nSometimes it's quicker to test the contents of a page rather than [`cy.visit()`](/llm/markdown/api/commands/visit.md) and wait for the entire page and all of its resources to load.\n\n```\ncy.request('/admin').its('body').should('include', '<h1>Admin</h1>')\n```\n",
      "section": "api",
      "anchors": [
        "issue-an-http-request"
      ],
      "path": "/llm/json/chunked/api/commands/request.json",
      "token_estimate": 47
    },
    {
      "id": "api/commands/request#method-url-and-body",
      "doc_id": "api/commands/request",
      "heading": "Method, URL, and Body",
      "heading_level": 3,
      "content_markdown": "### Method, URL, and Body\n\n#### Send a `POST` request with a JSON body\n\n```\ncy.request('POST', 'http://localhost:8888/users/admin', { name: 'Jane' }).then(  (response) => {    // response.body is automatically serialized into JSON    expect(response.body).to.have.property('name', 'Jane') // true  })\n```\n",
      "section": "api",
      "anchors": [
        "method-url-and-body"
      ],
      "path": "/llm/json/chunked/api/commands/request.json",
      "token_estimate": 49
    },
    {
      "id": "api/commands/request#send-a-post-request-with-a-json-body",
      "doc_id": "api/commands/request",
      "heading": "Send a POST request with a JSON body",
      "heading_level": 4,
      "content_markdown": "#### Send a `POST` request with a JSON body\n\n```\ncy.request('POST', 'http://localhost:8888/users/admin', { name: 'Jane' }).then(  (response) => {    // response.body is automatically serialized into JSON    expect(response.body).to.have.property('name', 'Jane') // true  })\n```\n",
      "section": "api",
      "anchors": [
        "send-a-post-request-with-a-json-body"
      ],
      "path": "/llm/json/chunked/api/commands/request.json",
      "token_estimate": 43
    },
    {
      "id": "api/commands/request#options",
      "doc_id": "api/commands/request",
      "heading": "Options",
      "heading_level": 3,
      "content_markdown": "### Options\n\n#### Request a page while disabling auto redirect\n\nTo test the redirection behavior of a login without a session, `cy.request` can be used to check the `status` and `redirectedToUrl` property.\n\nThe `redirectedToUrl` property is a special Cypress property that normalizes the URL the browser would normally follow during a redirect.\n\n```\ncy.request({  url: '/dashboard',  followRedirect: false, // turn off following redirects}).then((resp) => {  // redirect status code is 302  expect(resp.status).to.eq(302)  expect(resp.redirectedToUrl).to.eq('http://localhost:8082/unauthorized')})\n```\n\n#### Download a PDF file\n\nBy passing the `encoding: binary` option, the `response.body` will be serialized binary content of the file. You can use this to access various file types via `.request()` like `.pdf`, `.zip`, or `.doc` files.\n\n```\ncy.request({  url: 'http://localhost:8080/some-document.pdf',  encoding: 'binary',}).then((response) => {  cy.writeFile('path/to/save/document.pdf', response.body, 'binary')})\n```\n\n#### Get Data URL of an image\n\nBy passing the `encoding: base64` option, the `response.body` will be base64-encoded content of the image. You can use this to construct a [Data URI](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs) for use elsewhere.\n\n```\ncy.request({  url: 'https://docs.cypress.io/img/logo.png',  encoding: 'base64',}).then((response) => {  const base64Content = response.body  const mime = response.headers['content-type'] // or 'image/png'  // see https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs  const imageDataUrl = `data:${mime};base64,${base64Content}`})\n```\n\n#### HTML form submissions using form option\n\nOftentimes, once you have a proper e2e test around logging in, there's no reason to continue to `cy.visit()` the login and wait for the entire page to load all associated resources before running any other commands. Doing so can slow down our entire test suite.\n\nUsing `cy.request()`, we can bypass all of this because it automatically gets and sets cookies as if the requests had come from the browser.\n\n```\ncy.request({  method: 'POST',  url: '/login_with_form', // baseUrl is prepend to URL  form: true, // indicates the body should be form urlencoded and sets Content-Type: application/x-www-form-urlencoded headers  body: {    username: 'jane.lane',    password: 'password123',  },})// to prove we have a sessioncy.getCookie('cypress-session-cookie').should('exist')\n```\n\n#### Using `cy.request()` for HTML Forms\n\n[Check out our example recipe using `cy.request()` for HTML web forms](/llm/markdown/app/references/recipes.md#Logging-In)\n",
      "section": "api",
      "anchors": [
        "options"
      ],
      "path": "/llm/json/chunked/api/commands/request.json",
      "token_estimate": 425
    },
    {
      "id": "api/commands/request#request-a-page-while-disabling-auto-redirect",
      "doc_id": "api/commands/request",
      "heading": "Request a page while disabling auto redirect",
      "heading_level": 4,
      "content_markdown": "#### Request a page while disabling auto redirect\n\nTo test the redirection behavior of a login without a session, `cy.request` can be used to check the `status` and `redirectedToUrl` property.\n\nThe `redirectedToUrl` property is a special Cypress property that normalizes the URL the browser would normally follow during a redirect.\n\n```\ncy.request({  url: '/dashboard',  followRedirect: false, // turn off following redirects}).then((resp) => {  // redirect status code is 302  expect(resp.status).to.eq(302)  expect(resp.redirectedToUrl).to.eq('http://localhost:8082/unauthorized')})\n```\n",
      "section": "api",
      "anchors": [
        "request-a-page-while-disabling-auto-redirect"
      ],
      "path": "/llm/json/chunked/api/commands/request.json",
      "token_estimate": 96
    },
    {
      "id": "api/commands/request#download-a-pdf-file",
      "doc_id": "api/commands/request",
      "heading": "Download a PDF file",
      "heading_level": 4,
      "content_markdown": "#### Download a PDF file\n\nBy passing the `encoding: binary` option, the `response.body` will be serialized binary content of the file. You can use this to access various file types via `.request()` like `.pdf`, `.zip`, or `.doc` files.\n\n```\ncy.request({  url: 'http://localhost:8080/some-document.pdf',  encoding: 'binary',}).then((response) => {  cy.writeFile('path/to/save/document.pdf', response.body, 'binary')})\n```\n",
      "section": "api",
      "anchors": [
        "download-a-pdf-file"
      ],
      "path": "/llm/json/chunked/api/commands/request.json",
      "token_estimate": 67
    },
    {
      "id": "api/commands/request#get-data-url-of-an-image",
      "doc_id": "api/commands/request",
      "heading": "Get Data URL of an image",
      "heading_level": 4,
      "content_markdown": "#### Get Data URL of an image\n\nBy passing the `encoding: base64` option, the `response.body` will be base64-encoded content of the image. You can use this to construct a [Data URI](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs) for use elsewhere.\n\n```\ncy.request({  url: 'https://docs.cypress.io/img/logo.png',  encoding: 'base64',}).then((response) => {  const base64Content = response.body  const mime = response.headers['content-type'] // or 'image/png'  // see https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs  const imageDataUrl = `data:${mime};base64,${base64Content}`})\n```\n",
      "section": "api",
      "anchors": [
        "get-data-url-of-an-image"
      ],
      "path": "/llm/json/chunked/api/commands/request.json",
      "token_estimate": 81
    },
    {
      "id": "api/commands/request#html-form-submissions-using-form-option",
      "doc_id": "api/commands/request",
      "heading": "HTML form submissions using form option",
      "heading_level": 4,
      "content_markdown": "#### HTML form submissions using form option\n\nOftentimes, once you have a proper e2e test around logging in, there's no reason to continue to `cy.visit()` the login and wait for the entire page to load all associated resources before running any other commands. Doing so can slow down our entire test suite.\n\nUsing `cy.request()`, we can bypass all of this because it automatically gets and sets cookies as if the requests had come from the browser.\n\n```\ncy.request({  method: 'POST',  url: '/login_with_form', // baseUrl is prepend to URL  form: true, // indicates the body should be form urlencoded and sets Content-Type: application/x-www-form-urlencoded headers  body: {    username: 'jane.lane',    password: 'password123',  },})// to prove we have a sessioncy.getCookie('cypress-session-cookie').should('exist')\n```\n",
      "section": "api",
      "anchors": [
        "html-form-submissions-using-form-option"
      ],
      "path": "/llm/json/chunked/api/commands/request.json",
      "token_estimate": 156
    },
    {
      "id": "api/commands/request#request-polling",
      "doc_id": "api/commands/request",
      "heading": "Request Polling",
      "heading_level": 3,
      "content_markdown": "### Request Polling\n\n#### Call `cy.request()` over and over again\n\nThis is useful when you're polling a server for a response that may take awhile to complete.\n\nAll we're really doing here is creating a recursive function. Nothing more complicated than that.\n\n```\n// a regular ol' function folksfunction req () {  cy    .request(...)    .then((resp) => {      // if we got what we wanted      if (resp.status === 200 && resp.body.ok === true)        // break out of the recursive loop        return      // else recurse      req()    })}cy  // do the thing causing the side effect  .get('button').click()  // now start the requests  .then(req)\n```\n",
      "section": "api",
      "anchors": [
        "request-polling"
      ],
      "path": "/llm/json/chunked/api/commands/request.json",
      "token_estimate": 135
    },
    {
      "id": "api/commands/request#call-cy-request-over-and-over-again",
      "doc_id": "api/commands/request",
      "heading": "Call cy.request() over and over again",
      "heading_level": 4,
      "content_markdown": "#### Call `cy.request()` over and over again\n\nThis is useful when you're polling a server for a response that may take awhile to complete.\n\nAll we're really doing here is creating a recursive function. Nothing more complicated than that.\n\n```\n// a regular ol' function folksfunction req () {  cy    .request(...)    .then((resp) => {      // if we got what we wanted      if (resp.status === 200 && resp.body.ok === true)        // break out of the recursive loop        return      // else recurse      req()    })}cy  // do the thing causing the side effect  .get('button').click()  // now start the requests  .then(req)\n```\n",
      "section": "api",
      "anchors": [
        "call-cy-request-over-and-over-again"
      ],
      "path": "/llm/json/chunked/api/commands/request.json",
      "token_estimate": 131
    },
    {
      "id": "api/commands/request#notes",
      "doc_id": "api/commands/request",
      "heading": "Notes",
      "heading_level": 2,
      "content_markdown": "## Notes\n\n### Debugging\n\n#### Request is not displayed in the Network Tab of Developer Tools\n\nCypress does not _actually_ make an XHR request from the browser. We are actually making the HTTP request from Cypress (in Node). So, you won't see the request inside of your Developer Tools.\n\n### CORS\n\n#### CORS is bypassed\n\nNormally when the browser detects a cross-origin HTTP request, it will send an `OPTIONS` preflight check to ensure the server allows cross-origin requests, but `cy.request()` bypasses CORS entirely.\n\n```\n// we can make requests to any external server, no problem.cy.request('https://www.google.com/webhp?#q=cypress.io+cors')  .its('body')  .should('include', 'Testing, the way it should be') // true\n```\n\n### Cookies\n\n#### Cookies are automatically sent and received\n\nBefore sending the HTTP request, we automatically attach cookies that would have otherwise been attached had the request come from the browser. Additionally, if a response has a `Set-Cookie` header, these are automatically set back on the browser cookies.\n\nIn other words, `cy.request()` transparently performs all of the underlying functions as if it came from the browser.\n\n### [`cy.intercept()`](/llm/markdown/api/commands/intercept.md)\n\n#### `cy.request()` sends requests to actual endpoints, bypassing those defined using `cy.intercept()`\n\nThe intention of `cy.request()` is to be used for checking endpoints on an actual, running server without having to start the front end application.\n\n### User agent\n\nTrying to change the `User-Agent`?\n\nSee [how to override the browser's default user agent](/llm/markdown/app/faq.md#Can-I-override-or-change-the-default-user-agent-the-browser-uses).\n",
      "section": "api",
      "anchors": [
        "notes"
      ],
      "path": "/llm/json/chunked/api/commands/request.json",
      "token_estimate": 303
    },
    {
      "id": "api/commands/request#debugging",
      "doc_id": "api/commands/request",
      "heading": "Debugging",
      "heading_level": 3,
      "content_markdown": "### Debugging\n\n#### Request is not displayed in the Network Tab of Developer Tools\n\nCypress does not _actually_ make an XHR request from the browser. We are actually making the HTTP request from Cypress (in Node). So, you won't see the request inside of your Developer Tools.\n",
      "section": "api",
      "anchors": [
        "debugging"
      ],
      "path": "/llm/json/chunked/api/commands/request.json",
      "token_estimate": 63
    },
    {
      "id": "api/commands/request#request-is-not-displayed-in-the-network-tab-of-developer-tools",
      "doc_id": "api/commands/request",
      "heading": "Request is not displayed in the Network Tab of Developer Tools",
      "heading_level": 4,
      "content_markdown": "#### Request is not displayed in the Network Tab of Developer Tools\n\nCypress does not _actually_ make an XHR request from the browser. We are actually making the HTTP request from Cypress (in Node). So, you won't see the request inside of your Developer Tools.\n",
      "section": "api",
      "anchors": [
        "request-is-not-displayed-in-the-network-tab-of-developer-tools"
      ],
      "path": "/llm/json/chunked/api/commands/request.json",
      "token_estimate": 60
    },
    {
      "id": "api/commands/request#cors",
      "doc_id": "api/commands/request",
      "heading": "CORS",
      "heading_level": 3,
      "content_markdown": "### CORS\n\n#### CORS is bypassed\n\nNormally when the browser detects a cross-origin HTTP request, it will send an `OPTIONS` preflight check to ensure the server allows cross-origin requests, but `cy.request()` bypasses CORS entirely.\n\n```\n// we can make requests to any external server, no problem.cy.request('https://www.google.com/webhp?#q=cypress.io+cors')  .its('body')  .should('include', 'Testing, the way it should be') // true\n```\n",
      "section": "api",
      "anchors": [
        "cors"
      ],
      "path": "/llm/json/chunked/api/commands/request.json",
      "token_estimate": 76
    },
    {
      "id": "api/commands/request#cors-is-bypassed",
      "doc_id": "api/commands/request",
      "heading": "CORS is bypassed",
      "heading_level": 4,
      "content_markdown": "#### CORS is bypassed\n\nNormally when the browser detects a cross-origin HTTP request, it will send an `OPTIONS` preflight check to ensure the server allows cross-origin requests, but `cy.request()` bypasses CORS entirely.\n\n```\n// we can make requests to any external server, no problem.cy.request('https://www.google.com/webhp?#q=cypress.io+cors')  .its('body')  .should('include', 'Testing, the way it should be') // true\n```\n",
      "section": "api",
      "anchors": [
        "cors-is-bypassed"
      ],
      "path": "/llm/json/chunked/api/commands/request.json",
      "token_estimate": 73
    },
    {
      "id": "api/commands/request#cookies",
      "doc_id": "api/commands/request",
      "heading": "Cookies",
      "heading_level": 3,
      "content_markdown": "### Cookies\n\n#### Cookies are automatically sent and received\n\nBefore sending the HTTP request, we automatically attach cookies that would have otherwise been attached had the request come from the browser. Additionally, if a response has a `Set-Cookie` header, these are automatically set back on the browser cookies.\n\nIn other words, `cy.request()` transparently performs all of the underlying functions as if it came from the browser.\n",
      "section": "api",
      "anchors": [
        "cookies"
      ],
      "path": "/llm/json/chunked/api/commands/request.json",
      "token_estimate": 88
    },
    {
      "id": "api/commands/request#cookies-are-automatically-sent-and-received",
      "doc_id": "api/commands/request",
      "heading": "Cookies are automatically sent and received",
      "heading_level": 4,
      "content_markdown": "#### Cookies are automatically sent and received\n\nBefore sending the HTTP request, we automatically attach cookies that would have otherwise been attached had the request come from the browser. Additionally, if a response has a `Set-Cookie` header, these are automatically set back on the browser cookies.\n\nIn other words, `cy.request()` transparently performs all of the underlying functions as if it came from the browser.\n",
      "section": "api",
      "anchors": [
        "cookies-are-automatically-sent-and-received"
      ],
      "path": "/llm/json/chunked/api/commands/request.json",
      "token_estimate": 85
    },
    {
      "id": "api/commands/request#cy-intercept",
      "doc_id": "api/commands/request",
      "heading": "cy.intercept()",
      "heading_level": 3,
      "content_markdown": "### [`cy.intercept()`](/llm/markdown/api/commands/intercept.md)\n\n#### `cy.request()` sends requests to actual endpoints, bypassing those defined using `cy.intercept()`\n\nThe intention of `cy.request()` is to be used for checking endpoints on an actual, running server without having to start the front end application.\n",
      "section": "api",
      "anchors": [
        "cy-intercept"
      ],
      "path": "/llm/json/chunked/api/commands/request.json",
      "token_estimate": 51
    },
    {
      "id": "api/commands/request#cy-request-sends-requests-to-actual-endpoints-bypassing-those-defined-using-cy-intercept",
      "doc_id": "api/commands/request",
      "heading": "cy.request() sends requests to actual endpoints, bypassing those defined using cy.intercept()",
      "heading_level": 4,
      "content_markdown": "#### `cy.request()` sends requests to actual endpoints, bypassing those defined using `cy.intercept()`\n\nThe intention of `cy.request()` is to be used for checking endpoints on an actual, running server without having to start the front end application.\n",
      "section": "api",
      "anchors": [
        "cy-request-sends-requests-to-actual-endpoints-bypassing-those-defined-using-cy-intercept"
      ],
      "path": "/llm/json/chunked/api/commands/request.json",
      "token_estimate": 48
    },
    {
      "id": "api/commands/request#rules",
      "doc_id": "api/commands/request",
      "heading": "Rules",
      "heading_level": 2,
      "content_markdown": "## Rules\n\n### Requirements [Learn about chaining commands](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Chains-of-Commands)\n\n*   `cy.request()` requires being chained off of `cy`.\n*   `cy.request()` requires that the server sends a response.\n*   `cy.request()` requires that the response status code be `2xx` or `3xx` when `failOnStatusCode` is `true`.\n\n### Assertions [Learn about assertions](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Assertions)\n\n*   `cy.request()` will only run assertions you have chained once, and will not [retry](/llm/markdown/app/core-concepts/retry-ability.md).\n\n### Timeouts [Learn about timeouts](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Timeouts)\n\n*   `cy.request()` can time out waiting for the server to respond.\n",
      "section": "api",
      "anchors": [
        "rules"
      ],
      "path": "/llm/json/chunked/api/commands/request.json",
      "token_estimate": 101
    },
    {
      "id": "api/commands/request#requirements-learn-about-chaining-commands",
      "doc_id": "api/commands/request",
      "heading": "Requirements Learn about chaining commands",
      "heading_level": 3,
      "content_markdown": "### Requirements [Learn about chaining commands](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Chains-of-Commands)\n\n*   `cy.request()` requires being chained off of `cy`.\n*   `cy.request()` requires that the server sends a response.\n*   `cy.request()` requires that the response status code be `2xx` or `3xx` when `failOnStatusCode` is `true`.\n",
      "section": "api",
      "anchors": [
        "requirements-learn-about-chaining-commands"
      ],
      "path": "/llm/json/chunked/api/commands/request.json",
      "token_estimate": 52
    },
    {
      "id": "api/commands/request#command-log",
      "doc_id": "api/commands/request",
      "heading": "Command Log",
      "heading_level": 2,
      "content_markdown": "## Command Log\n\n**_Request comments endpoint and test response_**\n\n```\ncy.request('https://jsonplaceholder.typicode.com/comments').then((response) => {  expect(response.status).to.eq(200)  expect(response.body).to.have.length(500)  expect(response).to.have.property('headers')  expect(response).to.have.property('duration')})\n```\n\nThe commands above will display in the Command Log as:\n\nWhen clicking on `request` within the command log, the console outputs the following:\n",
      "section": "api",
      "anchors": [
        "command-log"
      ],
      "path": "/llm/json/chunked/api/commands/request.json",
      "token_estimate": 55
    },
    {
      "id": "api/commands/request#history",
      "doc_id": "api/commands/request",
      "heading": "History",
      "heading_level": 2,
      "content_markdown": "## History\n\n| Version | Changes |\n| --- | --- |\n| [4.7.0](/llm/markdown/app/references/changelog.md#3-3-0) | Added support for `encoding` option. |\n| [3.3.0](/llm/markdown/app/references/changelog.md#3-3-0) | Added support for options `retryOnStatusCodeFailure` and `retryOnNetworkFailure`. |\n| [3.2.0](/llm/markdown/app/references/changelog.md#3-2-0) | Added support for any valid HTTP `method` argument including `TRACE`, `COPY`, `LOCK`, `MKCOL`, `MOVE`, `PURGE`, `PROPFIND`, `PROPPATCH`, `UNLOCK`, `REPORT`, `MKACTIVITY`, `CHECKOUT`, `MERGE`, `M-SEARCH`, `NOTIFY`, `SUBSCRIBE`, `UNSUBSCRIBE`, `SEARCH`, and `CONNECT`. |\n",
      "section": "api",
      "anchors": [
        "history"
      ],
      "path": "/llm/json/chunked/api/commands/request.json",
      "token_estimate": 87
    },
    {
      "id": "api/commands/request#see-also",
      "doc_id": "api/commands/request",
      "heading": "See also",
      "heading_level": 2,
      "content_markdown": "## See also\n\n*   [`cy.exec()`](/llm/markdown/api/commands/exec.md)\n*   [`cy.task()`](/llm/markdown/api/commands/task.md)\n*   [`cy.visit()`](/llm/markdown/api/commands/visit.md)\n*   [Recipe: Logging In - Single Sign on](/llm/markdown/app/references/recipes.md#Logging-In)\n*   [Recipe: Logging In - HTML Web Form](/llm/markdown/app/references/recipes.md#Logging-In)\n*   [Recipe: Logging In - XHR Web Form](/llm/markdown/app/references/recipes.md#Logging-In)\n*   [Recipe: Logging In - CSRF Tokens](/llm/markdown/app/references/recipes.md#Logging-In)\n",
      "section": "api",
      "anchors": [
        "see-also"
      ],
      "path": "/llm/json/chunked/api/commands/request.json",
      "token_estimate": 53
    }
  ]
}