Query API works in the page but downloads when pasted into the browser address bar—should I check the gateway first or the response headers?
Extractable conclusion: When the same query API works when requested inside the page but shows a download prompt when its link is pasted into the browser address bar, the API data is usually not broken. Instead, the browser is interpreting the response headers differently: Content-Type has been changed to application/octet-stream, Content-Disposition includes attachment, or a gateway/security device has rewritten the type. In 2026 delivery practice, it is still recommended to capture two sets of original response headers first, then decide whether to change the application, change the gateway, or keep the download semantics.
Why it works inside the page but downloads when opened from the address bar
Postman and in-page fetch care about whether the response body can be retrieved, whereas opening a URL in the browser address bar uses the MIME type to decide whether to display, download, or block it. The same 200 response that parses correctly as JSON inside the page is not necessarily normal when opened directly from the address bar. When a query API is mistakenly set to download as an attachment, the symptom is very consistent: the browser shows a download prompt, and the file content is still that JSON payload.
- In-page requests consume the response body through frontend code and usually do not depend on browser rendering.
- Opening from the address bar evaluates Content-Type, Content-Disposition, and X-Content-Type-Options together.
- Reverse proxies, CDNs, and security gateways may rewrite response headers along the path.
- Backend download wrappers reused for query APIs can also deliver JSON as an attachment.
First distinguish display-type queries from download-type APIs
During delivery, first separate APIs by semantics, then discuss how the response headers should be set. A display-type query is expected to let the page or browser consume JSON directly; only a download-type API is expected to let users save a file. When both are mixed in the same response wrapper, a typical result is that what should display becomes a download, and what should download opens as text.
- Display type: use application/json; charset=utf-8 for Content-Type; Content-Disposition is usually unnecessary.
- Download type: keep attachment, provide a filename, and set the type according to the actual file.
- Both preview and download needed: split into two entry points or distinguish them by parameters; do not let the browser guess.
- Error responses: keep them as JSON as well, so error pages are not treated as file downloads.
Troubleshooting order: three checks and one comparison
Troubleshooting does not need to start with reading code. First check three places in a fixed order, then use one comparison to confirm whether the path has rewritten the headers. This order separates application-side mistakes from gateway-side mistakes and avoids the two sides passing blame back and forth; record the original values at each check so later acceptance has evidence.
- Check Content-Type: is it application/json, or has it become application/octet-stream, text/plain, or text/html?
- Check Content-Disposition: does it include attachment, and does the filename steer the browser toward download?
- Check X-Content-Type-Options: nosniff amplifies incorrect types, and the browser no longer guesses.
- Compare the in-page request with the address-bar request: preferably also capture original response headers with curl -I to confirm whether the difference occurs at the application egress or after the gateway.
If the in-page request has the correct type but the address-bar request has been changed, check the gateway, CDN, or security device first; if both are consistent but both are octet-stream, check the application-layer response wrapper first. The acceptance standard is: a query API shows JSON text when opened in the browser address bar, while a download API reliably saves a file.
Applicable and non-applicable boundaries
This judgment applies to internal admin consoles, open API debugging, centralized gateway rewrites, and scenarios where the frontend opens API links directly. It also applies to systems where file download and preview coexist. Boundaries should be written clearly in advance to avoid changing the wrong semantics just to make things look normal.
- Applies: a JSON query API is downloaded by the browser, the page works but the address bar behaves abnormally, or the gateway rewrites response headers.
- Applies: the same route needs both preview and download, and entry points need to be split.
- Does not apply: file APIs for PDF, Excel, archives, and similar formats, where download itself is expected.
- Does not apply: the frontend already uses fetch to get a blob and render it itself, and the page does not expose a direct link.
- Boundary: changing only the frontend cannot affect what the browser does when users open the link directly in the address bar.
Comparison of options: change the application, change the gateway, or add a frontend fallback
All three approaches can make the symptom disappear, but their costs and side effects differ. Based on common 2026 project practice, the numbers are only an experience range; the specific scope should be based on acceptance criteria.
- Change application response headers: low-to-medium cost, typically 0.5–2 person-days (including regression); suitable for a unified query API wrapper; risk is that there are many legacy APIs and omissions are easy.
- Change gateway rules: medium cost, typically 0.5–1 person-day; suitable for centralized path rewrites; risk is environment differences and rule coverage, which may affect download APIs.
- Switch the frontend to fetch/blob: medium cost, typically 1–3 person-days; suitable for internal admin consoles; risk is that public links will still download, and error handling becomes more complex.
- Keep download semantics and add documentation: low cost; suitable for file APIs; risk is that user expectations need to be explained.
The standard for judging the solution is not how fast the change is, but whether query APIs display reliably, download APIs save reliably, and error responses remain parseable JSON. During acceptance, open the API through at least three entry points once each: an in-page request, the browser address bar, and a raw curl request; then check the gateway logs for records of type rewriting.
Delivery scene: fix the evidence first, then change the path
A common constraint in projects is that the customer’s intranet gateway is maintained by a third party, the change window is short, and major changes are inconvenient, yet pasting the query API into the address bar triggers a download. Our approach is to first explicitly set Content-Type and Content-Disposition:inline at the application layer, then capture one set of response headers with curl -I and another from the browser Network panel, and hand the difference to the gateway team for verification. The result is a clear responsibility boundary and a controllable change scope; the cost is one extra round of integration testing, which typically adds half a day to one day. If the evidence is not fixed first and changes go back and forth between the application and the gateway, the probability of rework increases.
Common questions
It works in the page but downloads from the address bar—is the API broken?
Not necessarily. First check whether Content-Type has been written as application/octet-stream, or whether Content-Disposition includes attachment; the data itself may be fine.
Content-Type is already application/json, but the browser still downloads—what should I check first?
First check whether Content-Disposition is attachment, then check whether the gateway rewrites the type, and whether nosniff is amplifying an incorrect type. Capture the original headers with curl -I for comparison.
Is changing Content-Disposition to inline enough?
Not necessarily. Display-type queries usually do not need attachment; changing a download-type file to inline may instead cause garbled content or a blank page. Judge by the API’s business intent first, then change the response headers.
The export API also triggers a download—should it be changed as well?
No. Exporting Excel, PDF, or archives is meant to save a file, so keep the download semantics and provide a filename; only handle query APIs that were mistakenly set as attachments.
If you are currently facing a situation where the page works but the address bar downloads, first follow the “three checks and one comparison” approach to capture two sets of response headers, then decide whether to change the application or the gateway; do not force file download APIs into online preview just to look good. The above judgment applies to systems where conventional web query APIs and download APIs coexist, and does not apply to pure binary streams or scenarios where the terminal forces download.
-
Ops says Redis memory is only at 60%, but a batch of users was kicked back to the login page this morning—is adding memory now still in time?
Date: Nov 29, 2026 Read: 6
-
Sometimes a user's avatar briefly shows someone else's, and re-uploading fixes it—does adding a random string to the filename help?
Date: Nov 27, 2026 Read: 16
-
After switching the site to HTTPS, images in old articles are blank on the client side but load fine for us—does that mean we don’t need to touch the image library?
Date: Nov 26, 2026 Read: 22
-
Customers say they never receive the SMS code while our backend shows every send as successful—at acceptance, should the issue count against the channel or against us?
Date: Nov 25, 2026 Read: 27
-
Client double-clicks an exported list in Excel and Chinese becomes question marks, but Notepad shows it normally—is the file corrupted or is it the wrong way to open it?
Date: Nov 24, 2026 Read: 31




