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:
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.
I have solved my issue, so I'll relay the steps I took.
This is assuming that you are running an API locally, and that you want be able to access the localhost with your android emulator. For the record, my android emulator is running my xamarin app, but it should work for any app.
I will say, I haven't got the https Remove URL working yet. I get the error: Error: SecureChannelFailure (Authentication failed because the remote party has closed the transport stream.) . My API allows both HTTP and HTTPS requests, so HTTP works for me, but if I get HTTPS working, I'll add an edit with how I did it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.