From af65fd948bd21b6502bbd9beec15557f1d7a3ea3 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Wed, 9 Jan 2019 23:02:01 -0800 Subject: [PATCH] Start work on uploading the crash log. Create the URL request and the proper headers and form data. --- NetNewsWire/CrashReporter/CrashReporter.swift | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/NetNewsWire/CrashReporter/CrashReporter.swift b/NetNewsWire/CrashReporter/CrashReporter.swift index e1a68983e..2398cf1ab 100644 --- a/NetNewsWire/CrashReporter/CrashReporter.swift +++ b/NetNewsWire/CrashReporter/CrashReporter.swift @@ -7,6 +7,7 @@ // import Foundation +import RSWeb // Based originally on Uli Kusterer's UKCrashReporter: http://www.zathras.de/angelweb/blog-ukcrashreporter-oh-one.htm // Then based on the crash reporter included in NetNewsWire 3 and NetNewsWire Lite 4. @@ -93,7 +94,19 @@ struct CrashReporter { } static func sendCrashLogText(_ crashLogText: String) { - // TODO + let request = NSMutableURLRequest(url: URL(string: "https://ranchero.com/netnewswire/crashreportcatcher.php")!, cachePolicy: .reloadIgnoringLocalAndRemoteCacheData, timeoutInterval: 60.0) + request.httpMethod = HTTPMethod.post + + let boundary = "0xKhTmLbOuNdArY" + + let contentType = "multipart/form-data; boundary=%@\(boundary)" + request.setValue(contentType, forHTTPHeaderField:HTTPRequestHeader.contentType) + + let formString = "--\(boundary)\r\nContent-Disposition: form-data; name=\"crashlog\"\r\n\r\n\(crashLogText)\r\n--\(boundary)--\r\n" + let formData = formString.data(using: .utf8, allowLossyConversion: true) + request.httpBody = formData + + // TODO: Implement one-shot-download method in RSWeb that takes a URL request. } static func runCrashReporterWindow(_ crashLog: CrashLog) {