Skip to content

Conversation

@bingbing-gui
Copy link

Updated image handling in VisionAgent to use byte array.

System.Net.Http.HttpRequestException: 'Response status code does not indicate success: 403 (Forbidden).'

Motivation and Context

Description

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

Updated image handling in VisionAgent to use byte array.

System.Net.Http.HttpRequestException: 'Response status code does not indicate success: 403 (Forbidden).'
Copilot AI review requested due to automatic review settings December 28, 2025 12:07
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR modifies the VisionAgent sample to fetch image bytes using HttpClient instead of passing a URI directly to the API. This change resolves a 403 Forbidden error that occurs when some image hosting services (like Wikipedia) block direct URI access from automated requests.

  • Changed image handling from URI-based (UriContent) to byte array-based (DataContent)
  • Added HttpClient with User-Agent header to download image bytes before sending to the agent
  • Maintains the same functional behavior while working around external service restrictions



using HttpClient httpClient = new();
httpClient.DefaultRequestHeaders.UserAgent.ParseAdd("Mozilla/5.0 (Windows NT 10.0; Win64; x64)");
Copy link

Copilot AI Dec 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The User-Agent header is added to work around the 403 Forbidden error, but there's no comment explaining why this is necessary. According to the coding guidelines, sample code should be well-documented with comments explaining the purpose of each step. Consider adding a comment above line 22 explaining that some image hosting services (like Wikipedia) require a User-Agent header to prevent automated scraping.

Copilot generated this review using guidance from repository custom instructions.
name: "VisionAgent",
instructions: "You are a helpful agent that can analyze images");


Copy link

Copilot AI Dec 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an extra blank line here that should be removed to maintain consistency with the coding style in other samples.

Suggested change

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant