C
C#•2y ago
AlexeyS

āœ… (solved) dot net cannot send post request to my endpoint

Hey guys, need some help understanding why my dotnet app is not working:
let btn = document.getElementById('submit');
let URL = 'localhost:8080/controller';
document.getElementById('result-value').value = false.toString();


btn.onclick = (e) => {
let req = new XMLHttpRequest();
req.open("POST", URL, true);

req.setRequestHeader("Content-Type", "application/json;charset=UTF-8");

req.onreadystatechange = function () {
if (req.readyState == XMLHttpRequest.DONE && req.status == 200) {
let answer = JSON.parse(req.response);
if (typeof (answer.access) != 'undefined') {
document.getElementById('result-value').value = answer.access.toString();
}
}
}
req.send(JSON.stringify({
Login: document.getElementById('login').value,
Password: document.getElementById('pass').value
}));
};
let btn = document.getElementById('submit');
let URL = 'localhost:8080/controller';
document.getElementById('result-value').value = false.toString();


btn.onclick = (e) => {
let req = new XMLHttpRequest();
req.open("POST", URL, true);

req.setRequestHeader("Content-Type", "application/json;charset=UTF-8");

req.onreadystatechange = function () {
if (req.readyState == XMLHttpRequest.DONE && req.status == 200) {
let answer = JSON.parse(req.response);
if (typeof (answer.access) != 'undefined') {
document.getElementById('result-value').value = answer.access.toString();
}
}
}
req.send(JSON.stringify({
Login: document.getElementById('login').value,
Password: document.getElementById('pass').value
}));
};
I have such js frontend that sends a post request to my 'localhost:8080/controller' I have such coontroller in my dotnet app:
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;

namespace YourNamespace.Controllers
{
[ApiController]
[Route("[controller]")]
public class LoginController : ControllerBase
{
private static readonly Dictionary<string, string> Users = new Dictionary<string, string>
{
{"admin", "admin"},
{"dsfsdf", "sdfsdf"}
};

[HttpPost]
public IActionResult Post([FromBody] LoginRequest request)
{
if (Users.TryGetValue(request.Login, out var password) && password == request.Password)
{
return Ok(new { access = true });
}

return Ok(new { access = false });
}
}

public class LoginRequest
{
public string Login { get; set; }
public string Password { get; set; }
}
}
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;

namespace YourNamespace.Controllers
{
[ApiController]
[Route("[controller]")]
public class LoginController : ControllerBase
{
private static readonly Dictionary<string, string> Users = new Dictionary<string, string>
{
{"admin", "admin"},
{"dsfsdf", "sdfsdf"}
};

[HttpPost]
public IActionResult Post([FromBody] LoginRequest request)
{
if (Users.TryGetValue(request.Login, out var password) && password == request.Password)
{
return Ok(new { access = true });
}

return Ok(new { access = false });
}
}

public class LoginRequest
{
public string Login { get; set; }
public string Password { get; set; }
}
}
69 Replies
AlexeyS
AlexeySOP•2y ago
here is my program.cs file:
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run("http://localhost:8080");
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run("http://localhost:8080");
ero
ero•2y ago
Your url is wrong
AlexeyS
AlexeySOP•2y ago
in js file?
ero
ero•2y ago
Your controller sits at /login Yes
AlexeyS
AlexeySOP•2y ago
I thought: [Route("[controller]")] means /controller
ero
ero•2y ago
No, that would be [Route("controller")] The brackets format the class name
AlexeyS
AlexeySOP•2y ago
gotcha well, changed it and still doesn't work
AlexeyS
AlexeySOP•2y ago
AlexeyS
AlexeySOP•2y ago
let URL = 'localhost:8080/login';
Pobiega
Pobiega•2y ago
not sure you can issue requests like that from a file:// use live-server or similar to run your frontend so it uses the http protocol you're getting a CORS error because your frontend and backend have different origins atm so you'll also need to disable CORS in .NET
AlexeyS
AlexeySOP•2y ago
hmm
AlexeyS
AlexeySOP•2y ago
well it appears to be working if I send it by curl
Pobiega
Pobiega•2y ago
well yes, since CURL uses the http protocol šŸ™‚ unlike file:// also, CURL issues a raw http request. its not a browser, so there is no CORS going on. CORS is a client-side thing built into browsers to prevent redirect attacks
AlexeyS
AlexeySOP•2y ago
so what's the fastest way to "host" my html file?
Pobiega
Pobiega•2y ago
are you using VS Code?
AlexeyS
AlexeySOP•2y ago
yup
Pobiega
Pobiega•2y ago
Name: Live Server Id: ritwickdey.LiveServer Description: Launch a development local Server with live reload feature for static & dynamic pages Version: 5.7.9 Publisher: Ritwick Dey VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer
Live Server - Visual Studio Marketplace
Extension for Visual Studio Code - Launch a development local Server with live reload feature for static & dynamic pages
AlexeyS
AlexeySOP•2y ago
basically I have this
Pobiega
Pobiega•2y ago
this get this extension
AlexeyS
AlexeySOP•2y ago
AlexeyS
AlexeySOP•2y ago
hosted at 127.0.0.1/5500
Pobiega
Pobiega•2y ago
good now, fix the CORS issue in your program.cs
AlexeyS
AlexeySOP•2y ago
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run("http://localhost:8080");
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run("http://localhost:8080");
I've never used c# before in my life
Pobiega
Pobiega•2y ago
app.UseCors(corsPolicyBuilder =>
{
corsPolicyBuilder.AllowAnyOrigin();
corsPolicyBuilder.AllowAnyMethod();
corsPolicyBuilder.AllowAnyHeader();
});
app.UseCors(corsPolicyBuilder =>
{
corsPolicyBuilder.AllowAnyOrigin();
corsPolicyBuilder.AllowAnyMethod();
corsPolicyBuilder.AllowAnyHeader();
});
this will "disable" cors by allowing everything
AlexeyS
AlexeySOP•2y ago
well
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.UseCors(corsPolicyBuilder =>
{
corsPolicyBuilder.AllowAnyOrigin();
corsPolicyBuilder.AllowAnyMethod();
corsPolicyBuilder.AllowAnyHeader();
});

app.Run("http://localhost:8080");
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.UseCors(corsPolicyBuilder =>
{
corsPolicyBuilder.AllowAnyOrigin();
corsPolicyBuilder.AllowAnyMethod();
corsPolicyBuilder.AllowAnyHeader();
});

app.Run("http://localhost:8080");
I put it like that still getting cors errors
Pobiega
Pobiega•2y ago
well yes it needs to go before any other app.Use middleware order matters
AlexeyS
AlexeySOP•2y ago
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

app.UseCors(corsPolicyBuilder =>
{
corsPolicyBuilder.AllowAnyOrigin();
corsPolicyBuilder.AllowAnyMethod();
corsPolicyBuilder.AllowAnyHeader();
});

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();


app.Run("http://localhost:8080");
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

app.UseCors(corsPolicyBuilder =>
{
corsPolicyBuilder.AllowAnyOrigin();
corsPolicyBuilder.AllowAnyMethod();
corsPolicyBuilder.AllowAnyHeader();
});

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();


app.Run("http://localhost:8080");
Pobiega
Pobiega•2y ago
looks better.
AlexeyS
AlexeySOP•2y ago
just right after app declaration
AlexeyS
AlexeySOP•2y ago
AlexeyS
AlexeySOP•2y ago
just sent a post request via curl:
warn: Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware[3]
Failed to determine the https port for redirect.
warn: Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware[3]
Failed to determine the https port for redirect.
logged this
Pobiega
Pobiega•2y ago
thats a different middleware, probably not related. okay, lets re-order some middleware and add another
AlexeyS
AlexeySOP•2y ago
I'm ready
Pobiega
Pobiega•2y ago
app.UseHttpsRedirection();
app.UseRouting();
app.UseCors(corsPolicyBuilder =>
{
corsPolicyBuilder.AllowAnyOrigin();
corsPolicyBuilder.AllowAnyMethod();
corsPolicyBuilder.AllowAnyHeader();
});
app.UseHttpsRedirection();
app.UseRouting();
app.UseCors(corsPolicyBuilder =>
{
corsPolicyBuilder.AllowAnyOrigin();
corsPolicyBuilder.AllowAnyMethod();
corsPolicyBuilder.AllowAnyHeader();
});
AlexeyS
AlexeySOP•2y ago
what parts of code should I delete to put this
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

app.UseHttpsRedirection();
app.UseRouting();
app.UseCors(corsPolicyBuilder =>
{
corsPolicyBuilder.AllowAnyOrigin();
corsPolicyBuilder.AllowAnyMethod();
corsPolicyBuilder.AllowAnyHeader();
});

app.Run("http://localhost:8080");
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

app.UseHttpsRedirection();
app.UseRouting();
app.UseCors(corsPolicyBuilder =>
{
corsPolicyBuilder.AllowAnyOrigin();
corsPolicyBuilder.AllowAnyMethod();
corsPolicyBuilder.AllowAnyHeader();
});

app.Run("http://localhost:8080");
like this?
Pobiega
Pobiega•2y ago
uhm you removed all the middleware after cors, including your controller mapping
AlexeyS
AlexeySOP•2y ago
true
Pobiega
Pobiega•2y ago
dont do that :p re add everything after cors, except HttpsRedirection
AlexeyS
AlexeySOP•2y ago
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

app.UseHttpsRedirection();
app.UseRouting();
app.UseCors(corsPolicyBuilder =>
{
corsPolicyBuilder.AllowAnyOrigin();
corsPolicyBuilder.AllowAnyMethod();
corsPolicyBuilder.AllowAnyHeader();
});

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}


app.UseAuthorization();

app.MapControllers();


app.Run("http://localhost:8080");
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

app.UseHttpsRedirection();
app.UseRouting();
app.UseCors(corsPolicyBuilder =>
{
corsPolicyBuilder.AllowAnyOrigin();
corsPolicyBuilder.AllowAnyMethod();
corsPolicyBuilder.AllowAnyHeader();
});

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}


app.UseAuthorization();

app.MapControllers();


app.Run("http://localhost:8080");
Pobiega
Pobiega•2y ago
looks better give it a spin
AlexeyS
AlexeySOP•2y ago
still nope :(
Pobiega
Pobiega•2y ago
hang on, creating a new project to test
AlexeyS
AlexeySOP•2y ago
AlexeyS
AlexeySOP•2y ago
by the way
Pobiega
Pobiega•2y ago
yeah, CORS errors. but we already knew that can you pass me your html?
AlexeyS
AlexeySOP•2y ago
sure
MODiX
MODiX•2y ago
Please don't upload any potentially harmful files @AlexeyS, your message has been removed
AlexeyS
AlexeySOP•2y ago
let btn = document.getElementById('submit');
let URL = 'localhost:8080/login';
document.getElementById('result-value').value = false.toString();


btn.onclick = (e) => {
let req = new XMLHttpRequest();
req.open("POST", URL, true);

req.setRequestHeader("Content-Type", "application/json;charset=UTF-8");

req.onreadystatechange = function () {
if (req.readyState == XMLHttpRequest.DONE && req.status == 200) {
let answer = JSON.parse(req.response);
if (typeof (answer.access) != 'undefined') {
document.getElementById('result-value').value = answer.access.toString();
}
}
}
req.send(JSON.stringify({
Login: document.getElementById('login').value,
Password: document.getElementById('pass').value
}));
};
let btn = document.getElementById('submit');
let URL = 'localhost:8080/login';
document.getElementById('result-value').value = false.toString();


btn.onclick = (e) => {
let req = new XMLHttpRequest();
req.open("POST", URL, true);

req.setRequestHeader("Content-Type", "application/json;charset=UTF-8");

req.onreadystatechange = function () {
if (req.readyState == XMLHttpRequest.DONE && req.status == 200) {
let answer = JSON.parse(req.response);
if (typeof (answer.access) != 'undefined') {
document.getElementById('result-value').value = answer.access.toString();
}
}
}
req.send(JSON.stringify({
Login: document.getElementById('login').value,
Password: document.getElementById('pass').value
}));
};
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<link href="main.css" rel="stylesheet" />
</head>
<body>
<div class="wrapper">
<input id="login" type="text" placeholder="enter ur name" />
<input id="pass" type="password" placeholder="enter ur password" />
<button id="submit">Log In</button>
<div id="result">
<input id="result-value" type="text" disabled="disabled"/>
</div>
</div>
<script src="main.js"></script>
</body>
</html>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<link href="main.css" rel="stylesheet" />
</head>
<body>
<div class="wrapper">
<input id="login" type="text" placeholder="enter ur name" />
<input id="pass" type="password" placeholder="enter ur password" />
<button id="submit">Log In</button>
<div id="result">
<input id="result-value" type="text" disabled="disabled"/>
</div>
</div>
<script src="main.js"></script>
</body>
</html>
body {
margin: 0px;
padding:0px;
box-sizing:border-box;
user-select:none;
}

.wrapper {
margin: 200px auto 0 auto;
padding: 30px;
border: 2px solid #808080;
border-radius: 5px;
width: 50%;
}

.wrapper input {
border: 1px solid #808080;
border-radius: 3px;
font-size: 16px;
letter-spacing: 2px;
background-color: #dcdcdc;
width: 80%;
margin: 50px auto;
padding: 5px;
outline: none;
}

#submit {
display: block;
width: 100px;
cursor: pointer;
background-color: #9bffa6;
border: none;
outline: none;
padding: 10px;
border-radius: 5px;
}

#submit:hover {
transition: .5s all ease;
background-color:#67fa3d;
}

#result {
width:120px;
background-color:#97f5ef;
padding:10px 20px;
margin:50px auto;
text-align:center;
border-radius:5px;
}

#result input{
width:100%;
height:100%;
margin:0;
padding:0;
background-color:transparent;
border:none;
outline:none;
user-select:none;
text-align:center;
}
body {
margin: 0px;
padding:0px;
box-sizing:border-box;
user-select:none;
}

.wrapper {
margin: 200px auto 0 auto;
padding: 30px;
border: 2px solid #808080;
border-radius: 5px;
width: 50%;
}

.wrapper input {
border: 1px solid #808080;
border-radius: 3px;
font-size: 16px;
letter-spacing: 2px;
background-color: #dcdcdc;
width: 80%;
margin: 50px auto;
padding: 5px;
outline: none;
}

#submit {
display: block;
width: 100px;
cursor: pointer;
background-color: #9bffa6;
border: none;
outline: none;
padding: 10px;
border-radius: 5px;
}

#submit:hover {
transition: .5s all ease;
background-color:#67fa3d;
}

#result {
width:120px;
background-color:#97f5ef;
padding:10px 20px;
margin:50px auto;
text-align:center;
border-radius:5px;
}

#result input{
width:100%;
height:100%;
margin:0;
padding:0;
background-color:transparent;
border:none;
outline:none;
user-select:none;
text-align:center;
}
maybe something is wrong with my controller:
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;

namespace YourNamespace.Controllers
{
[ApiController]
[Route("[controller]")]
public class LoginController : ControllerBase
{
private static readonly Dictionary<string, string> Users = new Dictionary<string, string>
{
{"admin", "admin"},
{"dsfsdf", "sdfsdf"}
};

[HttpPost]
public IActionResult Post([FromBody] LoginRequest request)
{
if (Users.TryGetValue(request.Login, out var password) && password == request.Password)
{
return Ok(new { access = true });
}

return Ok(new { access = false });
}
}

public class LoginRequest
{
public string Login { get; set; }
public string Password { get; set; }
}
}
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;

namespace YourNamespace.Controllers
{
[ApiController]
[Route("[controller]")]
public class LoginController : ControllerBase
{
private static readonly Dictionary<string, string> Users = new Dictionary<string, string>
{
{"admin", "admin"},
{"dsfsdf", "sdfsdf"}
};

[HttpPost]
public IActionResult Post([FromBody] LoginRequest request)
{
if (Users.TryGetValue(request.Login, out var password) && password == request.Password)
{
return Ok(new { access = true });
}

return Ok(new { access = false });
}
}

public class LoginRequest
{
public string Login { get; set; }
public string Password { get; set; }
}
}
Pobiega
Pobiega•2y ago
nah thats not it the cors is the issue for sure, but I cant seem to reproduce for some reason
AlexeyS
AlexeySOP•2y ago
well yeah maybe something wrong with my pc after all idk
Pobiega
Pobiega•2y ago
I got it working when I swapped to fetch instead of using XmlRequest
AlexeyS
AlexeySOP•2y ago
hmm unfortunately I cannot change any front end code only backend
Pobiega
Pobiega•2y ago
okay.
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

app.UseHttpsRedirection();
app.UseRouting();

app.UseCors(x =>
{
x.AllowAnyHeader();
x.AllowAnyMethod();
x.AllowAnyOrigin();
});

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.UseAuthorization();

app.MapControllers();

app.Run();
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

app.UseHttpsRedirection();
app.UseRouting();

app.UseCors(x =>
{
x.AllowAnyHeader();
x.AllowAnyMethod();
x.AllowAnyOrigin();
});

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.UseAuthorization();

app.MapControllers();

app.Run();
thats my program.cs it works, no CORS errors
AlexeyS
AlexeySOP•2y ago
trying
Pobiega
Pobiega•2y ago
using .net 7 btw
AlexeyS
AlexeySOP•2y ago
me too hmm wait
AlexeyS
AlexeySOP•2y ago
still :(
Pobiega
Pobiega•2y ago
read the top error ah I know the issue your URL let URL = "https://localhost:7242/login"; you didnt specify a protocl in your URL
AlexeyS
AlexeySOP•2y ago
yess it works thanks man stupid error
Pobiega
Pobiega•2y ago
thats what we get for not reading the error message properly šŸ™‚
AlexeyS
AlexeySOP•2y ago
yup and it changes here to true
AlexeyS
AlexeySOP•2y ago
yeah thanks for help man, really appreciate it
Pobiega
Pobiega•2y ago
I would highly suggest using fetch and async instead of XmlHttpRequest thou
AlexeyS
AlexeySOP•2y ago
yeah but the code is not mine, that was a, let's say an "exercise"
Pobiega
Pobiega•2y ago
right
btn.onclick = async (e) => {
const response = await fetch(URL, { method: "POST" });
const content = await response.json();
resval.value = content.access;
};
btn.onclick = async (e) => {
const response = await fetch(URL, { method: "POST" });
const content = await response.json();
resval.value = content.access;
};
like, how much nicer is that šŸ˜„
AlexeyS
AlexeySOP•2y ago
decided to take a part in hackaton and they haven't even mentioned anywhere that you would need to write code in c# yeah looks way better
Angius
Angius•2y ago
Was about to say, why would anybody use XmlHttpRequest nowadays lol
SinFluxx
SinFluxx•2y ago
$close
MODiX
MODiX•2y ago
Use the /close command to mark a forum thread as answered

Did you find this page helpful?