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

Windows 11访问Debian 12上Ollama的cURL请求报错求助

问题:Windows 11客户端访问Debian 12上的Ollama API报错

在Debian 12机器部署Ollama后,本地及Debian客户端访问均正常,但Windows 11客户端调用API时出现JSON格式相关错误,多台Debian和Windows客户端测试结果一致。


一、Ollama服务器本地测试结果

http://localhost:11434/  正常
http://[本地IP]:11434/ 正常
curl https://www.google.com  正常
curl http://localhost:11434/api/generate -d '{ "model": "llava",  "prompt": "Why is the sky blue?", "stream": false}'    正常

二、Debian客户端测试结果

所有上述请求均正常

三、Windows 11客户端测试结果

http://服务器IP:11434/  正常
curl https://www.google.com 正常
curl http://服务器IP:11434/api/generate -d '{ "model": "llava",  "prompt": "Why is the sky blue?", "stream": false}'    报错,详情如下:

报错信息:

{"error":"invalid character '\'' looking for beginning of value"}curl: (3) URL rejected: Port number was not a decimal number between 0 and 65535
curl: (3) URL rejected: Bad hostname
curl: (3) URL rejected: Port number was not a decimal number between 0 and 65535
curl: (3) URL rejected: Malformed input to a URL function
curl: (3) URL rejected: Port number was not a decimal number between 0 and 65535
curl: (3) unmatched close brace/bracket in URL position 6:
false}'
     ^

解决思路

  1. 修正Windows下curl的JSON引号转义方式
    Windows CMD/PowerShell对引号的解析逻辑与Linux不同,需调整命令格式:
  • 若使用CMD:将外层单引号替换为双引号,内部双引号转义为\"
    curl http://服务器IP:11434/api/generate -d "{ \"model\": \"llava\",  \"prompt\": \"Why is the sky blue?\", \"stream\": false}"
    
  • 若使用PowerShell:推荐用哈希表生成标准JSON,避免手动转义
    $body = @{
        model  = "llava"
        prompt = "Why is the sky blue?"
        stream = $false
    } | ConvertTo-Json
    curl http://服务器IP:11434/api/generate -Method Post -Body $body -ContentType "application/json"
    
  1. 统一Windows应用的JSON请求规范
    其他Windows应用报错核心原因也是JSON格式问题:
  • 强制设置请求头Content-Type: application/json
  • 检查JSON字符串的引号闭合情况,避免混用单双引号或出现未转义的特殊字符
  • 先用Postman等工具验证请求格式正确性,再移植到目标应用中
  1. 排查网络层潜在干扰
    虽然基础访问正常,但需排除防火墙或代理的影响:
  • 临时关闭Windows防火墙,或添加11434端口的双向通行规则
  • 暂停代理软件,尝试直接连接服务器IP测试请求

内容的提问来源于stack exchange,提问作者Royce E Tuck

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.24 23:25:21