Posts

Showing posts with the label asp.net-core-webapi

How do I implement Post([FromBody] IMessage msg) in my .Net Core 2.1 web api Controller?

Image
Clash Royale CLAN TAG #URR8PPP How do I implement Post([FromBody] IMessage msg) in my .Net Core 2.1 web api Controller? I get the following exception when I send a simple JSON structure implementing the interface IMessage: Could not create an instance of type TestService2.IMessage. Type is an interface or abstract class and cannot be instantiated. Path 'Id', line 2, position 7. Action parameters by default have to be concrete classes that can be initialized by the model binder. Only custom model binders can be used to achieve what it is you are trying to do. – Nkosi Jul 27 at 14:53 My question would be Why do you want to use am interface for the model parameter? – Nkosi Jul 27 at 15:00 ...

Disable AutoRedirect in FlurlClient

Image
Clash Royale CLAN TAG #URR8PPP Disable AutoRedirect in FlurlClient I am using FlurlHttp and I want to disable AllowAutoRedirect for some API calls. I know How can I get System.Net.Http.HttpClient to not follow 302 redirects? WebRequestHandler webRequestHandler = new WebRequestHandler(); webRequestHandler.AllowAutoRedirect = false; HttpClient httpClient = new HttpClient(webRequestHandler); // Send a request using GetAsync or PostAsync Task<HttpResponseMessage> response = httpClient.GetAsync("http://www.google.com") But for Flurl I found only the way similar to described in C# Flurl - Add WebRequestHandler to FlurlClient (I haven't compiled yet the code below , so it may have some errors) public class HttpClientFactoryWithWebRequestHandler : DefaultHttpClientFactory { private readonly WebRequestHandler _webRequestHandler; public HttpClientFactoryWithWebRequestHandler (WebRequestHandler webRequestHandler ) { _webRequestHandler = webRequestHandler ;...

.net core Application is run with different port with electron.net with cross platrom

Image
Clash Royale CLAN TAG #URR8PPP .net core Application is run with different port with electron.net with cross platrom I've developed an application using .NET Core and Electron.NET and created one login form . .NET Core Electron.NET For login , I have created separate web API project and call the login API on login button click. web API When I call API from an application, Its give an error about "Cross-Origin", so I need to register an IP Address and Port in that API but right now I am facing an issue like .net core application is run on the different-different port each time. IP Address Port .net core While call sign-in in API from the window environment it gives me below port: 8001 While calling the same API from the Ubuntu it gives me port 35941 . So now I am facing an issue like, we have the different project for web API and it allows us to call web API on the specific port but due to each time different port generated by the electron.net, we can not call the ...