From d5c2cae89a5275c40cafa70fd59ae79523625081 Mon Sep 17 00:00:00 2001 From: Vance Chi Date: Wed, 31 Jan 2024 01:26:08 +0800 Subject: [PATCH] Add content-type header (#101) --- src/api/provider.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/api/provider.ts b/src/api/provider.ts index d38d95c..ab96a93 100644 --- a/src/api/provider.ts +++ b/src/api/provider.ts @@ -52,9 +52,16 @@ export class FetchProvider implements APIProvider { async call(args: {path: string; params?: unknown; method?: APIMethods}) { const url = this.url + args.path + + const reqBody = args.params !== undefined ? JSON.stringify(args.params) : undefined + const reqHeaders = {} + if (reqBody) { + reqHeaders['Content-Type'] = 'application/json' + } const response = await this.fetch(url, { method: args.method || 'POST', - body: args.params !== undefined ? JSON.stringify(args.params) : undefined, + body: reqBody, + headers: reqHeaders, }) const text = await response.text() let json: any