我尝试在方法中调用我的 API,但出现错误:{StatusCode: 415, ReasonPhrase: 'Unsupported Media Type'。我一直在环顾四周,发现很多人都遇到了同样的问题,但是通过在创建 StringContent 时添加媒体类型已经解决了。我已经设置了字符串内容,但仍然出现错误。
这是我尝试调用 API 的方法:
[HttpGet]
public async Task<ActionResult> TimeBooked(DateTime date, int startTime, int endTime, int id)
{
var bookingTable = new BookingTableEntity
{
BookingSystemId = id,
Date = date,
StartTime = startTime,
EndTime = endTime
};
await Task.Run(() => AddBooking(bookingTable));
var url = "http://localhost:60295/api/getsuggestions/";
using (var client = new HttpClient())
{
var content = new StringContent(JsonConvert.SerializeObject(bookingTable), Encoding.UTF8, "application/json");
var response = await client.GetAsync(string.Format(url, content));
string result = await response.Content.ReadAsStringAsync();
var timeBookedModel = …Run Code Online (Sandbox Code Playgroud) I'm trying to create a list and insert values in to it. But when I add a new item it changes all existing items in the list to the same value I add and I don't understand why.
Here is my code:
public List<Times> CreateListOfTimes()
{
var listOfTimes = new List<Times>();
var times = new Times();
int startTime = 8;
int endTime = startTime + 1;
for (int i = 0; i < 8; i++)
{
times.StartTime = startTime;
times.EndTime …Run Code Online (Sandbox Code Playgroud)