.net core 3.1 application running under IIS 8.5 win 2012 R2
I try to push notification using WebRequest through this website but I get timeout. it's flustrating because when i write the same WebRequest in Postman or even in debugging mode in Visual Studio it's working!
Problem is when the Application is trying to post webrequest to fcm.googleapis.com
- User fills up form,
- User POSTs to web application,
- Application creates another WebRequest with data from user post to fcm.googleapis.com and submits POST form in order to push notification to android devices
Web Form for users
[HttpPost]
public async Task<IActionResult> Create(CreateViewModel vm)
{
var request = new CreateRequest()
{
Author = String.IsNullOrEmpty(User.Identity.Name) ? "Guest" : User.Identity.Name,
Description = vm.Description,
};
var response = await _notificationService.Create(request);
vm.IsValid = response.IsSuccessfull;
vm.ShowBaseMessage = true;
vm.BaseMessage = response.Message;
return View("_CreateModalPartial", vm);
}
This data is passed to service which is responsible for submiting notifications
WebRequest for notification
try
{
var tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send");
tRequest.Method = "post";
tRequest.Headers.Add(string.Format("Authorization: key={0}", "apiKey"));
tRequest.Headers.Add(string.Format("Sender: id={0}", "senderId"));
tRequest.ContentType = "application/json";
var payload = new
{
to = clientToken,
data = new
{
author = author,
description = description
}
};
string postbody = JsonConvert.SerializeObject(payload).ToString();
Byte[] byteArray = Encoding.UTF8.GetBytes(postbody);
tRequest.ContentLength = byteArray.Length;
using (Stream dataStream = await tRequest.GetRequestStreamAsync())
{
dataStream.Write(byteArray, 0, byteArray.Length);
using (WebResponse tResponse = tRequest.GetResponse())
{
using (Stream dataStreamResponse = tResponse.GetResponseStream())
{
if (dataStreamResponse != null)
using (StreamReader tReader = new StreamReader(dataStreamResponse))
{
String sResponseFromServer = tReader.ReadToEnd();
//result.Response = sResponseFromServer;
}
}
}
}
}
catch(Exception e)
{
_logger.LogWarning(e.Message);
}
ALL TESTED DIRECTLY IN SERVER.. not external PC,
I have even installed Visual Studio in win 2012 R2 to debug in there but the problem doesnt show up while dubbing.. only after publishing it to IIS 8.5
question from:
https://stackoverflow.com/questions/65858111/webrequest-not-working-on-iis-but-works-in-visual-studio-debugging-or-postman 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…