You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

能否用Dredd工具连接公共API端点?连接报错EAI_AGAIN求助

Can Dredd connect to public API endpoints instead of localhost?

Absolutely! Dredd is fully designed to work with public remote API endpoints—it’s one of its key use cases for validating that your API contract matches the behavior of a live production or third-party service. That said, the Error:getaddrINFO EAI_AGAIN you’re hitting is a DNS resolution failure, which means Dredd can’t resolve the domain name of your target endpoint. Let’s break down how to fix this:

Common Fixes for EAI_AGAIN Error with Public Endpoints

1. Ensure Your Endpoint URL Includes the Full Protocol Prefix

This is the most common culprit. Your example endpoint api.openweathermap.org/data/2.5/weather?lat=35&lon=139 is missing the http:// or https:// prefix. Without this, Dredd treats the entire string as a hostname to resolve, which fails (since api.openweathermap.org/data/2.5/weather?lat=35&lon=139 isn’t a valid domain).

Fix this by using the complete URL in your Dredd config:

  • In your dredd.yml:
    endpoint: "https://api.openweathermap.org/data/2.5/weather?lat=35&lon=139"
    
  • Or when running Dredd via command line:
    dredd your-contract.yml "https://api.openweathermap.org/data/2.5/weather?lat=35&lon=139"
    

2. Verify DNS Resolution in Your Environment

Since Postman works, but Dredd doesn’t, check if your terminal environment can resolve the domain:

  • Run ping api.openweathermap.org in the same terminal you use to launch Dredd. If this fails, your system’s DNS settings are the issue. Try switching to a public DNS like Google’s 8.8.8.8 or Cloudflare’s 1.1.1.1.
  • If ping works but Dredd still fails, test with curl to confirm connectivity:
    curl "https://api.openweathermap.org/data/2.5/weather?lat=35&lon=139"
    
    If curl succeeds but Dredd doesn’t, check for proxy settings (see next point).

3. Configure Proxy Settings (If Needed)

If your network uses a proxy, Postman might be configured to use it automatically, but Dredd won’t unless you explicitly set it:

  • Set proxy environment variables before running Dredd:
    export HTTP_PROXY=http://your-proxy-address:port
    export HTTPS_PROXY=http://your-proxy-address:port
    dredd your-contract.yml "https://api.openweathermap.org/data/2.5/weather?lat=35&lon=139"
    
  • Or pass the proxy directly via Dredd’s command line flag:
    dredd your-contract.yml "https://api.openweathermap.org/data/2.5/weather?lat=35&lon=139" --proxy http://your-proxy-address:port
    

4. Update Dredd and Node.js

Older versions of Dredd or Node.js can have bugs related to DNS resolution or network requests:

  • Update Dredd to the latest version:
    npm install -g dredd
    
  • Ensure you’re running a supported Node.js LTS version (16.x or newer is recommended).

5. Escape Special Characters in the URL

If your endpoint includes query parameters, make sure they’re properly handled by your terminal. For example, the & character in your query string might be interpreted as a command separator. Wrapping the entire URL in quotes (as shown in earlier examples) fixes this.


内容的提问来源于stack exchange,提问作者sachu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 07:04:39