yadavdep
asked on
Dot net core api is not getting value
I have a dot net core API which has a method
Now from PostMan when I am testing this api and sends this json data
"{
"Username": "xxx116@clsdsddp.com"
}"
I always gets null in the username.
I have set the content type to application/json.
Not sure where I am making the mistake
Now from PostMan when I am testing this api and sends this json data
"{
"Username": "xxx116@clsdsddp.com"
}"
I always gets null in the username.
I have set the content type to application/json.
Not sure where I am making the mistake
using Autofac.Multitenant;
using CLIPITC.CORE.Helper;
using CLIPITC.CORE.Middlewares;
using CLIPITC.Repositories.Interfaces;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Serilog;
using System;
using System.Threading.Tasks;
using Utils;
using static System.Net.WebRequestMethods;
namespace CLIPITC_CORE.Controllers
{
[ServiceFilter(typeof(CustomActionFilter))]
[Produces("application/json")]
[Route("~/api/[Action]")]
public class AccountController : Controller
{
IAccountRepository _accountRepo;
public AccountController(IAccountRepository accountRepo, ITenantIdentificationStrategy service)
{
_accountRepo = accountRepo;
(service as MultitenantResolver).Init(_accountRepo);
}
[HttpPut]
public ActionResult RemoveMobileIDForUser(string Username)
{
if (Username.IsNull())
return new BadRequestObjectResult("UserName Can't be empty");
var response = _accountRepo.RemoveRememberMeOptionFromUser(Username);
return new ObjectResult(response);
}
}
}
ASKER
I am getting an Bad request error that is because of code written in the method
the strange part is if I remove the content type from the request then it works without any issue.
The expected is just true or false {Result:true}
if (Username.IsNull())
return new BadRequestObjectResult("UserName Can't be empty");
the strange part is if I remove the content type from the request then it works without any issue.
The expected is just true or false {Result:true}
I am getting an Bad request error that is because of code written in the method
Ok, think you are getting an 404 error here.
so you need to make sure you pass in the correct header and body request to your web service
ASKER
Yes, I checked that part already
Also,
Like I said before also
the strange part is if I remove the content type from the request then it works without any issue.
Also,
Like I said before also
the strange part is if I remove the content type from the request then it works without any issue.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Yes, Postman is also checked
Postman is also checkedso now you got a bad request 404 returned or with a response with status 200?
ASKER
I got it working
I was sending the Json in wrong form.
I jus sent "ddd@dasdadsa.com" and it worked
I was sending the Json in wrong form.
I jus sent "ddd@dasdadsa.com" and it worked
are you getting a response status 200 in your Postman request?
try debug the object : response before you return it.
how's the expected JSON response looks like?