Answer the question
In order to leave comments, you need to log in
Web Api method parameter(POST) was coming null?
Make a project with React.js + Redux on the client and WebApi.Net on the backend, the problem is that for some reason the parameters of the POST request from the client:
//webApiConfigure.js
...
if (process.env.NODE_ENV !== 'production') {
instance = axios.create({
baseURL: 'http://localhost:2270/api/',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
});
}
...
//signupform.js
import api from '../webApiConfigure'
...
api.post('/Message/', {
text: '121321',
AuthorTwitterHandle: '3123123',
})
.then((response) => {
console.log(response);
});
...
[EnableCors("*", "*", "*")]
public class MessageController : ApiController
{
public HttpResponseMessage Post([FromBody]ChatMessage message) //пробовал без FromBody, без толку
{
if (message == null || !ModelState.IsValid)
{
return Request.CreateErrorResponse(
HttpStatusCode.BadRequest,
"Invalid input");
}
messages.Add(message);
return Request.CreateResponse(HttpStatusCode.Created);
}
}
Answer the question
In order to leave comments, you need to log in
The problem was solved, at random ... deleted the line
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question