From 0557109b36ff4a6b7245e852a7d1b3148693e2fa Mon Sep 17 00:00:00 2001 From: Wesley de Groot Date: Fri, 10 Jan 2025 16:32:05 +0100 Subject: [PATCH] Fix posting --- .../SimpleNetworking/createHTTPBody.swift | 10 ---------- .../SimpleNetworking/SimpleNetworking/request.swift | 5 ++--- Sources/SimpleNetworking/Structs/NetworkResponse.swift | 1 + 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/Sources/SimpleNetworking/SimpleNetworking/createHTTPBody.swift b/Sources/SimpleNetworking/SimpleNetworking/createHTTPBody.swift index fdfce6e..b0c5644 100644 --- a/Sources/SimpleNetworking/SimpleNetworking/createHTTPBody.swift +++ b/Sources/SimpleNetworking/SimpleNetworking/createHTTPBody.swift @@ -74,16 +74,6 @@ extension SimpleNetworking { return nil } - // Get post encoding - func getPostEncoding(data: Any?) -> POSTEncoding { - if let string = data as? String, - string.contains("{") && string.contains("}") { - return .json - } - - return .plain - } - /// Content-Type Header for internal use func getContentType(postType: POSTEncoding = .json) -> String { switch postType { diff --git a/Sources/SimpleNetworking/SimpleNetworking/request.swift b/Sources/SimpleNetworking/SimpleNetworking/request.swift index 09030fb..5303351 100644 --- a/Sources/SimpleNetworking/SimpleNetworking/request.swift +++ b/Sources/SimpleNetworking/SimpleNetworking/request.swift @@ -46,9 +46,8 @@ extension SimpleNetworking { switch method { case .delete(let data), .post(let data), .patch(let data), .put(let data): - let newEncoding: POSTEncoding = getPostEncoding(data: data) - request.setValue(getContentType(postType: newEncoding), forHTTPHeaderField: "Content-Type") - request.httpBody = createHTTPBody(with: data, postType: newEncoding) + request.setValue(getContentType(postType: encoding), forHTTPHeaderField: "Content-Type") + request.httpBody = createHTTPBody(with: data, postType: encoding) case .get: break diff --git a/Sources/SimpleNetworking/Structs/NetworkResponse.swift b/Sources/SimpleNetworking/Structs/NetworkResponse.swift index 7195f4e..fad813c 100644 --- a/Sources/SimpleNetworking/Structs/NetworkResponse.swift +++ b/Sources/SimpleNetworking/Structs/NetworkResponse.swift @@ -131,6 +131,7 @@ extension SimpleNetworking { return try decoder.decode(T.self, from: data) } catch { print("\(file):\(line) \(function):\r\nDecoding error", error) + print("Raw string: \"\(self.string ?? "")\".") return nil } }