I am writing a Telegram Bot as a project in my internship. It aims to help customers easily view reports on their company's sales and send them message notifications(using a Webhook).
For most of the reports, I make a request to an API I wrote which generates and returns them as a byte array/JSON Object. The expected result is a byte array, and that is the case for most of them.
However, one of the reports returns a 404 and contains multiple question marks in the Uri- which I did not add.
https://url/?EpumpReport?/Company?/CompanyVarianceReport
The expected behaviour is a 200 OK, and the pdf content.
I have tried initializing the HttpClient inside of the class instead of registering it in the Startup. I have also tried sending the requests a different way by creating a HttpRequestMessage and sending that. All to no avail.
I wrote this function to reduce clutter:
GetReportWithSummaryDataAsync(message, Uri, _userData)
.
The message parameter contains a ChatId that identifies the user and a messageId that identifies the message.
_client.DefaultRequestHeaders.Add("Authorization", $"Bearer {userData.AuthKey}");
var requestMessage = new HttpRequestMessage(HttpMethod.Get, uri);
var response = await _client.SendAsync(requestMessage).ConfigureAwait(false);
var content = await response.Content.ReadAsStreamAsync();
var result = await JsonSerializer.DeserializeAsync<SummaryData>(content);
// Todo add check for NullReferenceException
_pdfReport = new MemoryStream(result.pdfReport);
return result;
This is the function itself. After this, I send the content of the result to the user.
The main issue is the Uri changing on its own.
Say I send a request to https://google.com/example
, when the request is about to be/being sent, the Uri changes to https://?google.com?/example?
And, I don't know why.
It turns out there were hidden characters present in my URI string. A frontend dev in the company mentioned their experience with a similar issue; then, I used this tool to find and remove the characters from the string. It works as it should now.