2025-08-29 17:19:54 [XNIO-1 task-3] INFO o.r.c.w.i.PlusWebInvokeTimeInterceptor - 域名信息:localhost 2025-08-29 17:19:54 [XNIO-1 task-3] DEBUG o.r.c.w.i.PlusWebInvokeTimeInterceptor - [PLUS]开始请求 => URL[POST /chat/send],参数类型[json],参数:[{"max_tokens":1024,"model":"qwen:7b","temperature":0.5,"top_p":1,"presence_penalty":0,"frequency_penalty":0,"messages":[{"role":"user","content":"你好"}],"stream":true,"kid":"","chat_type":0,"appId":"","reason":true}] 2025-08-29 17:19:54 [OkHttp http://127.0.0.1:11434/...] INFO o.r.c.c.o.interceptor.OpenAILogger - OkHttp-------->:--> POST http://127.0.0.1:11434/api/chat 2025-08-29 17:19:54 [OkHttp http://127.0.0.1:11434/...] INFO o.r.c.c.o.interceptor.OpenAILogger - OkHttp-------->:Content-Type: application/json; charset=utf-8 2025-08-29 17:19:54 [OkHttp http://127.0.0.1:11434/...] INFO o.r.c.c.o.interceptor.OpenAILogger - OkHttp-------->:Content-Length: 509 2025-08-29 17:19:54 [OkHttp http://127.0.0.1:11434/...] INFO o.r.c.c.o.interceptor.OpenAILogger - OkHttp-------->:Accept: text/event-stream 2025-08-29 17:19:54 [OkHttp http://127.0.0.1:11434/...] INFO o.r.c.c.o.interceptor.OpenAILogger - OkHttp-------->:--> END POST 2025-08-29 17:19:55 [OkHttp http://127.0.0.1:11434/...] INFO o.r.c.c.o.interceptor.OpenAILogger - OkHttp-------->:<-- 200 OK http://127.0.0.1:11434/api/chat (400ms) 2025-08-29 17:19:55 [OkHttp http://127.0.0.1:11434/...] INFO o.r.c.c.o.interceptor.OpenAILogger - OkHttp-------->:Content-Type: application/x-ndjson 2025-08-29 17:19:55 [OkHttp http://127.0.0.1:11434/...] INFO o.r.c.c.o.interceptor.OpenAILogger - OkHttp-------->:Date: Fri, 29 Aug 2025 09:19:55 GMT 2025-08-29 17:19:55 [OkHttp http://127.0.0.1:11434/...] INFO o.r.c.c.o.interceptor.OpenAILogger - OkHttp-------->:Transfer-Encoding: chunked 2025-08-29 17:19:55 [OkHttp http://127.0.0.1:11434/...] INFO o.r.c.c.o.interceptor.OpenAILogger - OkHttp-------->:<-- END HTTP 2025-08-29 17:19:57 [OkHttp http://127.0.0.1:11434/...] ERROR o.r.c.l.SSEEventSourceListener - OpenAI sse连接异常data:{"model":"qwen:7b","created_at":"2025-08-29T09:19:55.0570838Z","message":{"role":"assistant","content":"你好"},"done":false} {"model":"qwen:7b","created_at":"2025-08-29T09:19:55.3994008Z","message":{"role":"assistant","content":"!"},"done":false} {"model":"qwen:7b","created_at":"2025-08-29T09:19:55.5695375Z","message":{"role":"assistant","content":"有什么"},"done":false} {"model":"qwen:7b","created_at":"2025-08-29T09:19:55.7537292Z","message":{"role":"assistant","content":"关于"},"done":false} {"model":"qwen:7b","created_at":"2025-08-29T09:19:55.9369493Z","message":{"role":"assistant","content":"纪检"},"done":false} {"model":"qwen:7b","created_at":"2025-08-29T09:19:56.1242561Z","message":{"role":"assistant","content":"的问题"},"done":false} {"model":"qwen:7b","created_at":"2025-08-29T09:19:56.306915Z","message":{"role":"assistant","content":"我可以"},"done":false} {"model":"qwen:7b","created_at":"2025-08-29T09:19:56.4974082Z","message":{"role":"assistant","content":"帮你"},"done":false} {"model":"qwen:7b","created_at":"2025-08-29T09:19:56.6933964Z","message":{"role":"assistant","content":"解答"},"done":false} {"model":"qwen:7b","created_at":"2025-08-29T09:19:56.8960882Z","message":{"role":"assistant","content":"吗"},"done":false} {"model":"qwen:7b","created_at":"2025-08-29T09:19:57.1020841Z","message":{"role":"assistant","content":"?"},"done":false} {"model":"qwen:7b","created_at":"2025-08-29T09:19:57.3684137Z","message":{"role":"assistant","content":""},"done_reason":"stop","done":true,"total_duration":2710093600,"load_duration":20333100,"prompt_eval_count":81,"prompt_eval_duration":375209000,"eval_count":12,"eval_duration":2311252000} ,异常:{} java.lang.IllegalStateException: Invalid content-type: application/x-ndjson at okhttp3.internal.sse.RealEventSource.processResponse(RealEventSource.kt:60) at okhttp3.internal.sse.RealEventSource.onResponse(RealEventSource.kt:46) at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:519) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) at java.base/java.lang.Thread.run(Thread.java:842)
时间: 2025-08-29 18:50:37 AIGC 浏览: 33
`java.lang.IllegalStateException: Invalid content-type: application/x-ndjson` 异常通常表示代码试图处理不支持的 `Content-Type`。可以从以下几个方面解决该问题:
### 检查请求头设置
确保在发送请求时,正确设置了 `Content-Type` 头。如果请求不支持 `application/x-ndjson` 类型,需要修改为合适的类型。以下是使用 `HttpClient` 发送请求时设置 `Content-Type` 的示例代码:
```java
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class RequestExample {
public static void main(String[] args) throws IOException, InterruptedException {
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("http://example.com"))
.header("Content-Type", "application/json") // 修改为合适的类型
.POST(HttpRequest.BodyPublishers.ofString("{}"))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
```
### 服务器端支持
若服务器端不支持 `application/x-ndjson` 类型,需要在服务器端进行配置以支持该类型。例如,在 Spring Boot 项目中,可以通过配置 `WebMvcConfigurer` 来添加对 `application/x-ndjson` 的支持:
```java
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.mediaType("x-ndjson", MediaType.APPLICATION_NDJSON);
}
}
```
### 检查依赖库
确保使用的 HTTP 客户端库和服务器框架支持 `application/x-ndjson` 类型。某些旧版本的库可能不支持该类型,需要升级到支持的版本。
阅读全文
相关推荐



















