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

使用Fetch向Astrometry API提交URL时出现「no json」错误(SvelteKit+TS)

排查Astrometry API url_upload接口返回"no json"错误的方法

核心原因分析

Astrometry的url_upload接口不支持JSON格式的请求体,仅接受application/x-www-form-urlencoded或multipart/form-data格式的表单参数。你之前修改为application/json的操作不符合接口要求,这是问题未解决的关键。另外,即使使用表单格式,参数序列化错误或必填参数缺失也会触发该错误。

具体排查与修复步骤

  • 修正参数序列化方式
    若使用application/x-www-form-urlencoded,必须用URLSearchParams包裹参数,不能直接传递纯对象。示例代码:

    async function submitURL(sessionKey: string, imageUrl: string) {
      const params = new URLSearchParams({
        session_id: sessionKey,
        url: imageUrl
        // 可选参数如allow_commercial_use可按需添加
      });
    
      const res = await fetch('http://nova.astrometry.net/api/url_upload', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded'
        },
        body: params
      });
    
      return res.json();
    }
    

    也可使用FormData自动处理编码,无需手动设置Content-Type:

    async function submitURL(sessionKey: string, imageUrl: string) {
      const formData = new FormData();
      formData.append('session_id', sessionKey);
      formData.append('url', imageUrl);
    
      const res = await fetch('http://nova.astrometry.net/api/url_upload', {
        method: 'POST',
        body: formData
      });
    
      return res.json();
    }
    
  • 验证必填参数完整性
    确保session_id是fetchAstrometrySessionKey返回的有效密钥,且url参数为可公开访问的图片地址(Astrometry服务器需要能抓取到该图片,内网或带权限的URL会导致失败)。

  • 移除错误的Content-Type设置
    不要设置application/json请求头,接口无法解析JSON格式的请求体,会直接返回"no json"错误。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.31 13:25:50