File tree Expand file tree Collapse file tree 1 file changed +5
-1
lines changed
sample-code/spring-app/src/test/java/com/sap/ai/sdk/app/controllers Expand file tree Collapse file tree 1 file changed +5
-1
lines changed Original file line number Diff line number Diff line change 2424import com .sap .ai .sdk .orchestration .model .GenericModuleResult ;
2525import java .io .IOException ;
2626import java .io .InputStream ;
27+ import java .net .HttpURLConnection ;
2728import java .net .URL ;
2829import java .nio .charset .StandardCharsets ;
2930import java .nio .file .Files ;
@@ -323,7 +324,10 @@ void testImageInputBase64() {
323324 String dataUrl = "" ;
324325 try {
325326 URL url = new URL ("https://upload.wikimedia.org/wikipedia/commons/c/c9/Sap-logo-700x700.jpg" );
326- try (InputStream inputStream = url .openStream ()) {
327+ // the "User-Agent" header is required to avoid a 403
328+ HttpURLConnection connection = (HttpURLConnection ) url .openConnection ();
329+ connection .setRequestProperty ("User-Agent" , "Test implementation" );
330+ try (InputStream inputStream = connection .getInputStream ()) {
327331 byte [] imageBytes = inputStream .readAllBytes ();
328332 byte [] encodedBytes = Base64 .getEncoder ().encode (imageBytes );
329333 String encodedString = new String (encodedBytes , StandardCharsets .UTF_8 );
You can’t perform that action at this time.
0 commit comments