Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Sonja 82 posts 405 karma points
    1 week ago
    Sonja
    0

    making web api call from umbraco

    hi, I have a Umbraco web application that is supposed to make api call . When I do the api call from postman or from console application everything works perfectly. When I'm making the API call from umbraco I don't receive the response. I'm getting stuck on

      HttpResponseMessage response = await client.PostAsJsonAsync("api/user/login", request);
    

    The code is completely same in the console application and in the Umbraco application.

    Dud anyone had similar experience? Please advice how do I fix my problem and receive the response. Thanks

  • Alex Skrypnyk 4887 posts 17640 karma points MVP 2x admin c-trib
    1 week ago
    Alex Skrypnyk
    0

    Hi Sonja

    What is full request URL you are trying to use?

    Alex

  • Sonja 82 posts 405 karma points
    1 week ago
    Sonja
    0

    Hi Alex I'm setting the request url previously with

    client.BaseAddress = new Uri(ConfigurationManager.AppSettings["myUrl"]);
    

    and it is outside url, our service provider url. The web api is not in Umbraco, not in our domain but totally outside

  • Alex Skrypnyk 4887 posts 17640 karma points MVP 2x admin c-trib
    1 week ago
    Alex Skrypnyk
    0

    Hi Sonja

    Where in Umbraco do you run this code? Is it a controller or some service? event?

    Maybe there is an issue with async, that isn't working properly.

    Thanks,

    Alex

  • Sonja 82 posts 405 karma points
    7 days ago
    Sonja
    0

    Hi Alex,

    I'm running the code when a certain page is loaded, when I'm triggering GET of an MVC Controller. It is not inside the controller class but in another class. Is Umbraco blocking something and not allowing this kind of code to run? Please advice how do I proceed

    Thanks,

    Sonja

  • Alexander Croner 40 posts 181 karma points
    7 days ago
    Alexander Croner
    0

    I think you have to show more of the code in order for anyone to help you.

  • Sonja 82 posts 405 karma points
    7 days ago
    Sonja
    0

    This is how I'm sending the login request

    public static async Task<LoginResponse> LoginMyUser(LoginRequest request)
            {
                var loginResponse = new LoginResponse();
                client.BaseAddress = new Uri(ConfigurationManager.AppSettings["DGUrl"]);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                HttpResponseMessage response = await client.PostAsJsonAsync("api/user/login", request);
                response.EnsureSuccessStatusCode();
                if (response.IsSuccessStatusCode)
                {
                    var dataObject = response.Content.ReadAsAsync<LoginResponse>().Result;
                    loginResponse.token = dataObject.token;
                    loginResponse.sessionName = dataObject.sessionName;
                    loginResponse.sessionId = dataObject.sessionId;
    
                }
    
                loginDgResponse.response = response;
    
                return  loginDgResponse;
            }
    

    This is how I'm sending it

       var loginRequest = new LoginRequest()
                        {
                            username = ConfigurationManager.AppSettings["dusername"],
                            password = ConfigurationManager.AppSettings["dpassword"]
                        };
                        var getResponse = LoginUser.LoginMyUser(loginRequest).Result; 
    

    The code works perfectly in console application so it is not the code, it is some setting because I never received any response.

  • Sonja 82 posts 405 karma points
    7 days ago
    Sonja
    0

    I also did a simple MVC application and I got same results. I don't think it is Umbraco but something with IIS or IISExpress maybe

  • Sonja 82 posts 405 karma points
    5 days ago
    Sonja
    0

    Guys, I still have this problem. Even if it might be MVC related, did nobody ever had such problem and what might be a solution?

  • Tor Langlo 85 posts 205 karma points
    5 days ago
    Tor Langlo
    0

    If you monitor the request and response with Chrome Developer Tools’ Network tab, or similar, what do you see? What kind of response? Or timeout?

    -Tor

  • Sonja 82 posts 405 karma points
    5 days ago
    Sonja
    0

    in chrome I'm not seeing the api call. I only see the umbraco get page and it is returning me 302

  • Tor Langlo 85 posts 205 karma points
    4 days ago
    Tor Langlo
    0

    It might have something to do with how your configuring your HttpClient instance, so more information (code) would be helpful. I see you're using PostAsJsonAsync method, maybe you could replace that with your own code, making it synchronous and doing the json serialization yourself. This just to nail down the issue, once you have found the problem you might put the original code back in.

    Another thing you could do to see the network traffic is to use Fiddler or a similar tool. My suggestion to use Chrome Dev Tools will not work since the API call is not from the web client, but from your server.

    /Tor

  • Sonja 82 posts 405 karma points
    3 days ago
    Sonja
    0

    Hi Tor,

    I have tried with Fiddler, and I got Tunnel to the service provider, the result is 200, the response is empty, and the request I can't find. From the response I'm finding

    HTTP/1.1 200 Connection Established

    FiddlerGateway: Direct

    StartTime: 16:31:16.324

    Connection: close

    EndTime: 16:31:16.385

    ClientToServerBytes: 130

    ServerToClientBytes: 7

    Process:iisexpress:1224

    Did I send it correctly? Is the problem with the service provider? Is there some testing web api so I can try to send request there to see if it is going dorrectly from my side and it is not the service provider restriction? I asked the guys from the service provider and they said they don't have any restrictions.

    Please advice

  • Tor Langlo 85 posts 205 karma points
    23 hours ago
    Tor Langlo
    0

    If you could find your request in Fiddler, and then compare it to the success calls from postman or the console app you mentioned earlier, then that would be helpful.

    -Tor

Please Sign in or register to post replies

Write your reply to:

Draft