There is something weird with the passing parameter. The function is being called, I can debug it, but the request is always empty.
[EnableCors("SiteCorsPolicy")]
[ApiController]
[Route("api/[controller]")]
public class LineBotController : ControllerBase
{
private LineMessagingClient _lineMessagingClient;
public LineBotController()
{
_lineMessagingClient = new LineMessagingClient(Config._Configuration["Line:ChannelAccessToken"]);
}
[HttpPost]
public async Task<HttpResponseMessage> Post(HttpRequestMessage request)
{
try
{
var events = await request.GetWebhookEventsAsync(Config._Configuration["Line:ChannelSecret"]);
var app = new LineBotApp(_lineMessagingClient);
await app.RunAsync(events);
}
catch (Exception e)
{
Helpers.Log.Create("ERROR! " + e.Message);
}
return request.CreateResponse(HttpStatusCode.OK);
}
}
Is the HttpRequestMessage suppose to get every data from the request?
Some example of calling it:
var data = {
'to': 'xxx',
'messages':[
{
"type": "text",
"text": "Hello, world1"
},
{
"type": "text",
"text": "Hello, world2"
}
]
};
$.ajax({
type: 'POST',
contentType: "application/json; charset=utf-8",
dataType: 'json',
async: false,
data: JSON.stringify({request: data}),
url: url,
authorization: 'Bearer {Key}',
success: function (success) {
var x = success;
},
error: function (error) {
var x = error;
}
});
the url: https://localhost/api/LineBot
urlis setHttpRequestMessageorHttpResponseMessageso you need to clarify exactly what it is you are trying to do