From 57aabff184203647a6e607a96001b6448b921b72 Mon Sep 17 00:00:00 2001 From: seabaylea Date: Wed, 14 Sep 2016 14:23:02 +0100 Subject: [PATCH] Set Content-Type to application/x-www-form-urlencoded for POST requests --- Foundation/NSURLSession/NSURLSessionTask.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Foundation/NSURLSession/NSURLSessionTask.swift b/Foundation/NSURLSession/NSURLSessionTask.swift index ae14fbf7f9..ced3288d88 100644 --- a/Foundation/NSURLSession/NSURLSessionTask.swift +++ b/Foundation/NSURLSession/NSURLSessionTask.swift @@ -568,6 +568,8 @@ fileprivate extension URLSessionTask { easyHandle.set(requestMethod: request.httpMethod ?? "GET") if request.httpMethod == "HEAD" { easyHandle.set(noBody: true) + } else if ((request.httpMethod == "POST") && (request.value(forHTTPHeaderField: "Content-Type") == nil)) { + easyHandle.set(customHeaders: ["Content-Type:application/x-www-form-urlencoded"]) } } }