|
3 | 3 | using System.Linq; |
4 | 4 | using System.Net; |
5 | 5 | using System.Net.Http; |
| 6 | +using System.Net.Http.Headers; |
6 | 7 | using System.Text; |
7 | 8 | using System.Text.RegularExpressions; |
8 | 9 | using System.Threading; |
@@ -58,6 +59,16 @@ public partial class WebUntisClient : IDisposable |
58 | 59 | /// </summary> |
59 | 60 | private string _sessonId; |
60 | 61 |
|
| 62 | + /// <summary> |
| 63 | + /// The school name for the sesson |
| 64 | + /// </summary> |
| 65 | + private string _schoolName; |
| 66 | + |
| 67 | + /// <summary> |
| 68 | + /// The trace id for the sesson |
| 69 | + /// </summary> |
| 70 | + private string _traceId; |
| 71 | + |
61 | 72 | /// <summary> |
62 | 73 | /// Initialize a new client |
63 | 74 | /// </summary> |
@@ -201,7 +212,7 @@ public async Task LogoutAsync(string id = "Logout", CancellationToken ct = defau |
201 | 212 | Params = new object() |
202 | 213 | }; |
203 | 214 | StringContent requestContent = new StringContent(JsonConvert.SerializeObject(requestModel), Encoding.UTF8, "application/json"); |
204 | | - requestContent.Headers.Add("jsessionid", _sessonId); |
| 215 | + SetRequestHeaders(requestContent.Headers); |
205 | 216 |
|
206 | 217 | // Send request |
207 | 218 | _ = await _client.PostAsync(ServerUrl + "/WebUntis/jsonrpc.do", requestContent, ct); |
@@ -262,6 +273,7 @@ private async Task<TResult> MakeJSONRPCRequestAsync<TRequest, TResult>(string id |
262 | 273 | Params = requestParams |
263 | 274 | }; |
264 | 275 | StringContent requestContent = new StringContent(JsonConvert.SerializeObject(requestModel), Encoding.UTF8, "application/json"); |
| 276 | + SetRequestHeaders(requestContent.Headers); |
265 | 277 |
|
266 | 278 | // Send request |
267 | 279 | HttpResponseMessage response = await _client.PostAsync(ServerUrl + requestUrl, requestContent, ct); |
@@ -292,6 +304,17 @@ private async Task<TResult> MakeJSONRPCRequestAsync<TRequest, TResult>(string id |
292 | 304 | return responseModel.Result; |
293 | 305 | } |
294 | 306 |
|
| 307 | + /// <summary> |
| 308 | + /// Add the default headers to a WebUntis API request |
| 309 | + /// </summary> |
| 310 | + /// <param name="headers">The headers object to add</param> |
| 311 | + private void SetRequestHeaders(HttpHeaders headers) |
| 312 | + { |
| 313 | + headers.Add("JSESSIONID", _sessonId); |
| 314 | + headers.Add("schoolname", _schoolName); |
| 315 | + headers.Add("traceId", _traceId); |
| 316 | + } |
| 317 | + |
295 | 318 | #region IDisposable |
296 | 319 | private bool _disposedValue; |
297 | 320 |
|
|
0 commit comments