In my first screen of my app mobile
I'm doing is the Login screen, however whenever I try to log the return it is
StatusCode: 404,
ReasonPhrase: 'Not Found'
I have already confirmed and uri
is correct, access via postman normally, I started to suspect that something is missing to configure in the project or app
manifest, I already tested the project Android and UWP
all give the same problem.
What gave me this certainty is that I created a console app
just to test access to api
, everything works normally, it follows the code:
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.Net.Http;
namespace app1
{
class Program
{
static void Main(string[] args)
{
var url = "https://api.dominio.com.br/login";
var userName = "[email protected]";
var password = "12345678";
var token = GetToken(url, userName, password);
}
static string GetToken(string url, string userName, string password)
{
var pairs = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>( "username", userName ),
new KeyValuePair<string, string> ( "password", password )
};
var content = new FormUrlEncodedContent(pairs);
using (var client = new HttpClient())
{
var response = client.PostAsync(url, content).Result;
JObject o = JObject.Parse(response.Content.ReadAsStringAsync().Result);
return (string)o["token"];
}
}
}
}
How can I solve this problem?
On request I will put the code that is not working, although it is the same as the above code:
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
namespace AppMobile.Services
{
public class Auth : IAuthenticate
{
const string Url = "https://api.dominio.com.br/Login";
public async Task<string> GetToken(string user, string pass)
{
var pairs = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>( "username", user ),
new KeyValuePair<string, string> ( "password", pass )
};
var content = new FormUrlEncodedContent(pairs);
using (var client = new HttpClient())
{
var response = await client.PostAsync(Url, content);
JObject obj = JObject.Parse(response.Content.ReadAsStringAsync().Result);
var token = (string)obj["token"];
return token;
}
}
}
}