From 53bacbe314da61bb70f61e4be0ba5217c7e1265e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=82=E5=85=B5=E5=85=B5?= <43210631+bingbing-gui@users.noreply.github.com> Date: Sun, 28 Dec 2025 21:05:14 +0900 Subject: [PATCH] Modify VisionAgent to fetch and send image bytes Updated image handling in VisionAgent to use byte array. System.Net.Http.HttpRequestException: 'Response status code does not indicate success: 403 (Forbidden).' --- .../Agents/Agent_Step11_UsingImages/Program.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step11_UsingImages/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step11_UsingImages/Program.cs index f534e4edd7..4adeda20bc 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step11_UsingImages/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step11_UsingImages/Program.cs @@ -17,9 +17,14 @@ name: "VisionAgent", instructions: "You are a helpful agent that can analyze images"); + +using HttpClient httpClient = new(); +httpClient.DefaultRequestHeaders.UserAgent.ParseAdd("Mozilla/5.0 (Windows NT 10.0; Win64; x64)"); +byte[] imageBytes = await httpClient.GetByteArrayAsync("https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg"); + ChatMessage message = new(ChatRole.User, [ new TextContent("What do you see in this image?"), - new UriContent("https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg", "image/jpeg") + new DataContent(imageBytes, "image/jpeg") ]); var thread = agent.GetNewThread();