Steven 4 years ago
parent
commit
8f08a938fe

+ 10 - 10
MusicGradeExam/MusicGradeExam/Define/PrefixHeader.pch

@@ -85,11 +85,11 @@
 
 //#ifdef DEBUG
 
-//#define hostURL (@"https://test.kj.colexiu.com")
-//#define SEALCLASSHOST (@"https://test.kj.colexiu.com/api-im")
-//#define WEBHOST (@"https://test.m.kj.colexiu.com")
-//#define JSPUSH_ENVIRONMENT (NO)
-//#define RCIM_KEY (@"mgb7ka1nme0yg")
+#define hostURL (@"https://test.kj.colexiu.com")
+#define SEALCLASSHOST (@"https://test.kj.colexiu.com/api-im")
+#define WEBHOST (@"https://test.m.kj.colexiu.com")
+#define JSPUSH_ENVIRONMENT (NO)
+#define RCIM_KEY (@"mgb7ka1nme0yg")
 
 //#define hostURL (@"http://192.168.3.28:8000")
 //#define SEALCLASSHOST (@"http://192.168.3.28:8000/api-im")
@@ -105,11 +105,11 @@
 
 //#else    // 线上
 
-#define hostURL (@"https://kj.colexiu.com")
-#define SEALCLASSHOST (@"https://kj.colexiu.com/api-im")
-#define WEBHOST (@"https://m.kj.colexiu.com")
-#define JSPUSH_ENVIRONMENT (YES)
-#define RCIM_KEY (@"8w7jv4qb8zuyy")
+//#define hostURL (@"https://kj.colexiu.com")
+//#define SEALCLASSHOST (@"https://kj.colexiu.com/api-im")
+//#define WEBHOST (@"https://m.kj.colexiu.com")
+//#define JSPUSH_ENVIRONMENT (YES)
+//#define RCIM_KEY (@"8w7jv4qb8zuyy")
 
 //#endif
 

+ 4 - 2
MusicGradeExam/MusicGradeExam/KSRequestManager.m

@@ -25,7 +25,7 @@
 }
 
 + (void)clearRequestHeader {
-    [[KSNetworking shareManager] configHttpHeader:@{@"Authorization":@""}];
+    [[KSNetworking shareManager] removeHeaderKey];
 }
 
 // 设置表单提交方式
@@ -242,17 +242,19 @@
                    progress:(void(^)(int64_t bytesRead, int64_t totalBytes))progress
                     success:(void(^)(NSURL *fileUrl))success
                     faliure:(void(^)(NSError *error))faliure {
-    
+    [self clearRequestHeader];
     [[KSNetworking shareManager] downloadWithUrl:myUrl progressBlock:^(int64_t bytesRead, int64_t totalBytes) {
         if (progress) {
             progress(bytesRead, totalBytes);
         }
     } successBlock:^(NSURL * _Nullable url) {
+        [self configRequestHeader];
         if (success) {
             success(url);
         }
     } failBlock:^(NSError * _Nonnull error) {
         [self showMessage:@"网络或服务器错误,请重试"];
+        [self configRequestHeader];
         if (faliure) {
             faliure(error);
         }

+ 2 - 1
MusicGradeExam/MusicGradeExam/Tools/Category/UrlDecode.h

@@ -11,5 +11,6 @@
 @interface UrlDecode : NSObject
 
 + (NSString *)decodeStringWithString:(NSString *)encodeString;
-
+// url编码
++ (NSString *)encodeUrlStringWithString:(NSString *)urlString;
 @end

+ 5 - 0
MusicGradeExam/MusicGradeExam/Tools/Category/UrlDecode.m

@@ -15,4 +15,9 @@
     return decodeString;
 }
 
+// url编码
++ (NSString *)encodeUrlStringWithString:(NSString *)urlString {
+    NSString *encodedString  = [urlString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
+    return encodedString;
+}
 @end

+ 5 - 1
MusicGradeExam/MusicGradeExam/Tools/NetworkManager/KSNetworking.h

@@ -116,7 +116,11 @@ NS_ASSUME_NONNULL_BEGIN
  *  @param httpHeader 请求头
  */
 - (void)configHttpHeader:(NSDictionary *_Nonnull)httpHeader;
-
+/**
+ *  移除请求头
+ *
+ */
+- (void)removeHeaderKey;
 /**
  *  取消GET请求
  */

+ 13 - 1
MusicGradeExam/MusicGradeExam/Tools/NetworkManager/KSNetworking.m

@@ -143,6 +143,7 @@ static NSTimeInterval   requestTimeout = 15.0f;  // 超时时间
     if (responseObj && cache) {
         if (successBlock) successBlock(responseObj);
     }
+    url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
     session = [manager GET:url parameters:params headers:headers progress:^(NSProgress * _Nonnull downloadProgress) {
         if (progressBlock) progressBlock(downloadProgress.completedUnitCount,
                                          downloadProgress.totalUnitCount);
@@ -193,6 +194,7 @@ static NSTimeInterval   requestTimeout = 15.0f;  // 超时时间
     if (responseObj && cache) {
         if (successBlock) successBlock(responseObj);
     }
+    url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
     session = [manager POST:url parameters:params headers:headers progress:^(NSProgress * _Nonnull uploadProgress) {
         if (progressBlock) progressBlock(uploadProgress.completedUnitCount,
                                          uploadProgress.totalUnitCount);
@@ -245,6 +247,7 @@ static NSTimeInterval   requestTimeout = 15.0f;  // 超时时间
            return session;
        }
         __weak typeof(manager) weakManager = manager;
+    url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
        session = [manager POST:url parameters:parameters headers:headers constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
            NSString *fileName = nil;
            
@@ -367,7 +370,7 @@ static NSTimeInterval   requestTimeout = 15.0f;  // 超时时间
     NSString *type;
     NSArray *subStringArr;
     __block KSURLSessionTask *session = nil;
-    
+    url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
     NSURL *fileUrl = [[KSCacheManager shareManager] getDownloadDataFromCacheWithRequestUrl:url];
     
     if (fileUrl) {
@@ -528,6 +531,15 @@ static NSTimeInterval   requestTimeout = 15.0f;  // 超时时间
     }
 }
 
+/**
+ *  移除请求头
+ *
+ */
+- (void)removeHeaderKey {
+    headers = @{};
+    [self.httpSessionManager.requestSerializer clearAuthorizationHeader];
+}
+
 + (NSArray *)currentRunningTasks {
     return [[KSNetworking allTasks] copy];
 }