I've seen some similar issues, but nothing here seems to match my problem exactly.
I'm running a version of my API (C#) locally to test some updates. Its hooked up to a local SQL database.
When I run a query to get a token, postman works as expected. However, when I boot up my android emulator (xamarin) and run the same query, the requests times out with error code 0 almost instantly. I've set it to not time out at all. Another strange thing is that when I set the breakpoints in the local API, postman triggers those breakpoints, but the android app doesn't.
This is odd because both postman and the android app can query the live version of the API in the servers.
I've heard this might be a CORS issue?
Steps to reproduce the issue:
- Start up the local API which opens up a webpage to a local port.
- Test the port is working by sending a request with postman. The request I tried was requesting a token.
- Use postman to generate restsharp code, and run that code from inside the xamarin android project.
The error I get is always status code 0.
Code:
The following code was generated via postman after a successful request.
var client = new RestClient("http://localhost:53884/token");
client.Timeout = -1;
var request = new RestRequest(Method.GET);
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddHeader("Cookie", ".AspNet.Cookies=7u9...JRrb");
request.AddParameter("username", "redacted");
request.AddParameter("password", "redacted2");
request.AddParameter("grant_type", "password");
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
I can't share the API code due to IP, but it works for the app when running on the servers, and both locally and live for postman.