@@ -13,20 +13,24 @@ export class RestManager {
1313 const { method, path, body, headers } = options ;
1414 const url = `${ this . baseURL } /${ path } ` ;
1515
16- console . log ( `Sending ${ method } request to:` , url , "with body:" , body , "and headers:" , headers ) ;
17- let requestBody = body ;
18- const contentType = headers ?. [ "Content-Type" ] || headers ?. [ "content-type" ] ;
19- if ( body && contentType === "application/json" ) {
20- requestBody = JSON . stringify ( body ) ;
21- }
16+ let requestBody : unknown = undefined ;
17+ let requestHeaders : Record < string , string > = {
18+ "User-Agent" : "@game2822/smartschool.js" ,
19+ ...headers ,
20+ } ;
21+
22+ if ( body instanceof URLSearchParams ) {
23+ requestBody = body . toString ( ) ;
24+ requestHeaders [ "Content-Type" ] = "application/x-www-form-urlencoded" ;
25+ } else if ( body ) {
26+ requestBody = JSON . stringify ( body ) ;
27+ requestHeaders [ "Content-Type" ] = "application/json" ;
28+ }
29+
2230 const response = await fetch ( url , {
2331 method,
24- body : requestBody as any ,
25- headers : {
26- "Content-Type" : contentType || "application/json" ,
27- ...headers ,
28- "User-Agent" : "@game28/smartschool.js"
29- }
32+ body : requestBody ,
33+ headers : requestHeaders
3034 } ) ;
3135
3236 if ( ! response . ok ) {
0 commit comments