0

Every way found on internet regarding sending a request in C# .NET, and setting a custom header / authorization is only visible in the VS request, but when i check on fiddler it's not there. I don't believe it's a code problem, i think it has to do with something else.

Latest way tried:

        var form = new MultipartFormDataContent();
        form.Add(new ByteArrayContent(fileContent, 0, fileContent.Length), "image", filename);

        HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Post, URL)
        {
            Content = form
        };
        message.Headers.Authorization = new AuthenticationHeaderValue("Basic", AuthCode);
        var response = httpClient.SendAsync(message).Result;
        string apiResponse = response.Content.ReadAsStringAsync().Result;
Cata Hotea
  • 1,811
  • 1
  • 9
  • 19
  • 1
    The code definitely has a problem - instead of using `await` it uses `.Result` resulting in *blocking*. Don't do that. There's a reason HttpClient doesn't have blocking methods. As for the missing header, where is it, how is it called, where are you setting it? Your current code doesn't set any custom header – Panagiotis Kanavos Jun 29 '18 at 12:17
  • The code is only for auth. For header its not posted. But the problem persists to both situations. Why would it be in the header in vs but its not passed and seen in fiddler? I'll try using await instead of .Result – Cata Hotea Jun 29 '18 at 12:20
  • 1
    What header? Your code doesn't use any custom header. Are you saying that the Authorization header is missing perhaps? That's not a custom header. Most likely `AuthCode` whatever it is is wrong. What *is* `AuthCode` ? – Panagiotis Kanavos Jun 29 '18 at 12:21
  • Man listen what i'm saying. I posted code only for setting an auth. I used similar code to set a custom header but it has the same result => VISIBLE IN VS, NOT VISIBLE IN FIDDLER. – Cata Hotea Jun 29 '18 at 12:23
  • 1
    Don't say. Post the code that exhibits the problem. How is anyone supposed to guess what headers you are setting? HttpClient was released 6 years ago and used by hundreds of thousands of developers. It doesn't have any problem with headers. – Panagiotis Kanavos Jun 29 '18 at 12:25
  • In the meantime, check [this probably duplicate question](https://stackoverflow.com/questions/35907642/custom-header-to-httpclient-request/35910012) – Panagiotis Kanavos Jun 29 '18 at 12:26

0 Answers0