-2

i have 2 different api projects (1 shop, 2 bank) and when calling from shop to bank want to get caller info in bank api.

there is calling method

var connection = https://localhost:44355/ + @"api/costomer";

var response = await new HttpClient().GetAsync(connection + $"/{id}");

there is how i try to get info in bank api

var str = Request.Headers["Origin"];

archil.z
  • 1
  • 3
  • 1
    The question is not clear, could you please explain the what you want to do ? The current explanation is not sufficient to answer the question – Mandar Dharmadhikari May 04 '20 at 12:11
  • i have 2 application, one for shop, another for bank, I want to use http call from shop to bank api, and i want to check in bank api what domain or origin called my banks controller method – archil.z May 04 '20 at 12:19
  • Please take a look at the origin header that is sent to the API when a request is made, please have a look at following https://stackoverflow.com/questions/41365670/get-request-origin-in-c-sharp-api-controller If your calls are not cross origin, set the header while calling the API – Mandar Dharmadhikari May 04 '20 at 23:43

1 Answers1

0

HttpClient.GetAsync() sends a GET request to the specified Uri as an asynchronous operation.If you want to get the origin header value , you could refer to the below :

        var origin = Request.Scheme+"://"+Request.Host+Request.Path;
        var request = new HttpRequestMessage(
                    HttpMethod.Get,
                    "https://localhost:44389/api/test/get");
        request.Headers.Add("Origin", origin);
        var response = await new HttpClient().SendAsync(request);
Xueli Chen
  • 11,987
  • 3
  • 25
  • 36