求助:使用R向PACER Case Locator(PCL)发送HTTP GET请求遇404错误
Hey there, let's work through this 404 issue step by step—since both your httr request and browser are returning "Not Found", the problem is almost certainly tied to the request itself rather than authentication (though we’ll double-check that angle too). Here are the most likely fixes to try:
Verify your endpoint URL is 100% accurate
PACER's API endpoints have specific, non-negotiable paths. Even a tiny typo (like a missing hyphen, wrong version number, or extra trailing slash) will trigger a 404. Double-check against the official PCL API documentation you received—make sure you’re using the full, exact base URL and endpoint path (e.g., something likehttps://pacer.uscourts.gov/case-locator/v1/search). If you were relying on an older, deprecated endpoint, that could explain the error even if PACER says their API is operational.Include mandatory query parameters
Some PCL API endpoints won’t return a valid response unless you specify required parameters (like a court ID, case number, or date range). A generic request to a base endpoint without these might throw a 404 instead of a clear error message. Try adding the minimal required parameters from the docs to your request first, then build out to your desired query.Add critical HTTP headers
PACER’s API may expect specific headers to process your request correctly. Many APIs require aUser-Agentstring to identify the client, or anAcceptheader to define the response format you want. Modify yourhttrrequest to include these:library(httr) # Replace with your actual endpoint and credentials response <- GET( url = "YOUR_VALID_PCL_ENDPOINT", authenticate("your_pacer_username", "your_pacer_password"), add_headers( "User-Agent" = "R/httr Package", "Accept" = "application/json" ) ) # Inspect full response details for clues print(response) str(content(response))Confirm your PACER account has API access
Even if your username/password works for the PACER website, some accounts need explicit permission to use the PCL API. Reach out to PACER support again to verify your account is authorized for API requests—sometimes this is a separate setting that isn’t enabled by default.Test with a known-working example
Since otherhttrexamples work for you, try replicating a minimal, verified PCL API request from their documentation. For example, if there’s a sample request that returns a test case, use that exact URL and parameters to see if you get a 200 response. If that works, you can build out from there to your desired query.
内容的提问来源于stack exchange,提问作者Daniel Lee

