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
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
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.
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.
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.
Actually I have compared the both calls and both calls are OK. So this looks like the problem is when I receive the response. both calls have good request and response but my response is not received
Not sure if it's relevant, but the these two lines can be improved:
response.EnsureSuccessStatusCode();
if (response.IsSuccessStatusCode)
since the call to response.EnsureSuccessStatusCode() will throw an exception if response.IsSuccessStatusCode is false. In other words, you don't need the if statement.
I have tried to send post api call to a local web api, sent empty call and received the response but only when I remove await and add Result at the end.
I did the same in a new empty MVC application without Umbraco and I received my api response perfectly.
However when I do this in my umbraco application for the api call that worked in MVC application without Umbraco in Umbraco I'm getting error ""One or more errors occurred."" and InnerException {"The request was aborted: Could not create SSL/TLS secure channel."}
Good to hear you're getting further here! I'm probably a bit outside of my comfort zone now, but maybe there's something in your code after the the await call (i.e. in the call stack) which causes the request to complete or abort before the async call completes (and continues with the lines after the await)?
Are you using await calls to the top of the call stack?
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
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
Hi Sonja
What is full request URL you are trying to use?
Alex
Hi Alex I'm setting the request url previously with
and it is outside url, our service provider url. The web api is not in Umbraco, not in our domain but totally outside
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
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
I think you have to show more of the code in order for anyone to help you.
This is how I'm sending the login request
This is how I'm sending it
The code works perfectly in console application so it is not the code, it is some setting because I never received any response.
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
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?
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
in chrome I'm not seeing the api call. I only see the umbraco get page and it is returning me 302
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
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
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
Actually I have compared the both calls and both calls are OK. So this looks like the problem is when I receive the response. both calls have good request and response but my response is not received
So to be clear,
You see the json response in Fiddler?
You get stuck on the following line in your code?
since the call to response.EnsureSuccessStatusCode() will throw an exception if response.IsSuccessStatusCode is false. In other words, you don't need the if statement.
-Tor
Hi Tor,
yes
yes
Thanks I will fix this
So is the problem then narrowed down to either a problem with how the HttpClient is set up, or an issue with the underlying Umbraco web site?
Could you do a test using the same HttpClient set up against a different API and/or service and test it?
-Tor
Hi Tor,
I have tried to send post api call to a local web api, sent empty call and received the response but only when I remove await and add Result at the end.
But it was api call hosted on local.
I did the same in a new empty MVC application without Umbraco and I received my api response perfectly.
However when I do this in my umbraco application for the api call that worked in MVC application without Umbraco in Umbraco I'm getting error ""One or more errors occurred."" and InnerException {"The request was aborted: Could not create SSL/TLS secure channel."}
when I added in Global.asax.cs the line
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
started working but without awaitGood to hear you're getting further here! I'm probably a bit outside of my comfort zone now, but maybe there's something in your code after the the await call (i.e. in the call stack) which causes the request to complete or abort before the async call completes (and continues with the lines after the await)?
Are you using await calls to the top of the call stack?
-Tor
Hi Tor,
When I'm using await calls my call doesn't receive the response. So I have removed await almost everywhere in the code
-Sonja
is working on a reply...