Answer the question
In order to leave comments, you need to log in
How to make a post request from one site to another?
There are two sites: 1 site acts as a server, sends and receives data using asp.net web api, the second site acts as a client that makes get and post requests to the first site, written in asp.net mvc, requests are made in controllers using httpClient.
Get-requests work without problems, but there is a problem with the post-request - when trying to execute a request from the server, a 500th error is returned. At the same time, if the client site is launched on its local machine and executes the same requests to the server, then there are no problems.
I had thoughts that it was a matter of cross-domain requests, I was looking for information on this topic, but everywhere this problem is mentioned when making requests directly from js, I did not find anything about asp.net mvc. Maybe that's not the problem at all.
I would appreciate any information, thanks in advance!
UPDATE
Request code from client:
[HttpPost]
public string MakeOrder(int gameId, string orderTime, string customerName, string customerPhoneNumber)
{
var route = string.Format(@"api/service/MakeOrder");
var dto = new OrderDTO(gameId, orderTime, customerName, customerPhoneNumber);
var value = Tuple.Create(Tenant, dto);
using (var client = new HttpClient())
{
var url = this.baseUrl + route;
var serializedDto = client.GetStringAsync(url).Result;
var deserializedObject = Newtonsoft.Json.JsonConvert.DeserializeObject<T>(serializedDto,
new Newtonsoft.Json.JsonSerializerSettings
{
TypeNameHandling = Newtonsoft.Json.TypeNameHandling.Auto,
NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore,
});
return deserializedObject;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question