Home > database >  C# HTTP GET returns 404 Not Found
C# HTTP GET returns 404 Not Found

Time:12-26

I'm trying to download .webp image, and it always returns 404, but if I hardcode URI or smply open it in browser, it returns 200 with image.

Details:

string uri1 = "https://some.site/static/.../.../0.webp";
string uri2 = parsedApiResponse;
var response1 = client.GetAsync(uri1).Result;
var response2 = client.GetAsync(uri2).Result;
Log($"{response1.StatusCode}\n", ConsoleColor.Magenta);
Log($"{response2.StatusCode}\n", ConsoleColor.Yellow);

StatusCode

parsedApiResponse contains string reply from API (it saves image on server and returns it's location) with full path leading to .webp image.

uri1 contains hardcoded parsedApiResponse with handly copied path to other image from exactly same earlier call.

response1 returns exactly what it should when response2, from absoletely same request with not hardcoded URI, returns... this (Fiddler screenshots:)

raw inspection of successful request

raw inspection of fail request

It's absolutely same! There's no custom headers, no content, but response is different. And if I'll log and copy path of uri2 and then will paste it on place of uri1, it will turn the same way.

Content of response2 is a full cloudflare 404 page, but main part says this:

<section id="text">
  <div>
    <h1>Error 404</h1>
    <h3>This object could not be viewed</h3>
  </div>

  <div>
    <p id="error-title">**You are not authorized to view this object**</p>
    <p>
            This object does not exist or is not publicly accessible at this
            URL. Check the URL of the object that you're looking for or contact
            the owner to enable Public access.
    </p>
  </div>

  <div>
    <p id="footer-title">Is this your bucket?</p>
    <p>
      Learn how to enable
      <a
        href="https://developers.cloudflare.com/r2/data-access/public-buckets/">Public Access
      </a>
    </p>
  </div>
</section>

I've already tried to play with some HttpClientHandler params, tried to use other clients like RestClient and WebClient, tried to pass all possible headers to mimic my browser and many-many other stuff - no result. What can it be? Why does it require some authorize? How does hardcoded URI get's these credentials?..

  • Related