猎豆优选

TBSDKConnection.h 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //
  2. // TBSDKConnection.h
  3. // TBSDK
  4. //
  5. // Created by 亿刀 on 14-3-6.
  6. // Copyright (c) 2014年 Taobao.com. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. #import "TBSDKConnectionProtocol.h"
  10. @protocol TBSDKProgressDelegate;
  11. @protocol TBSDKConnectionDelegate;
  12. //和ASI对应轻易不要修改
  13. typedef enum _TBSDKNetworkErrorType {
  14. TBSDKConnectionFailureErrorType = 1,
  15. TBSDKRequestTimedOutErrorType = 2,
  16. TBSDKAuthenticationErrorType = 3,
  17. TBSDKRequestCancelledErrorType = 4,
  18. TBSDKUnableToCreateRequestErrorType = 5,
  19. TBSDKInternalErrorWhileBuildingRequestType = 6,
  20. TBSDKInternalErrorWhileApplyingCredentialsType = 7,
  21. TBSDKFileManagementError = 8,
  22. TBSDKTooMuchRedirectionErrorType = 9,
  23. TBSDKUnhandledExceptionError = 10,
  24. TBSDKCompressionError = 11,
  25. TBSDKACCSError = 12,
  26. } TBSDKNetworkErrorType;
  27. @interface TBSDKConnection : NSObject
  28. @property (weak,nonatomic) id<TBSDKProgressDelegate>uploadProgressDelegate;
  29. @property (nonatomic, strong) NSURL *url;
  30. @property (nonatomic, assign) TBSDKCachePolicy cachePolicy;
  31. @property (weak,nonatomic) id <TBSDKCacheDelegate> downloadCache;
  32. @property (weak,nonatomic) id <TBSDKProgressDelegate> downloadProgressDelegate;
  33. @property (assign, nonatomic) NSTimeInterval timeOutSeconds;
  34. @property (nonatomic, strong) NSDictionary *responseHeaders;
  35. @property (nonatomic, strong) NSMutableDictionary *requestHeaders;
  36. @property (nonatomic, strong) NSError *error;
  37. @property (nonatomic, weak) id<TBSDKConnectionDelegate>delegate;
  38. @property (nonatomic, strong) NSMutableArray *requestCookies;
  39. @property (nonatomic, strong) NSData *responseData;
  40. @property (nonatomic, strong) NSString *responseString;
  41. @property (nonatomic, assign) NSStringEncoding responseEncoding;
  42. @property (assign,nonatomic) int responseStatusCode;
  43. @property (assign,nonatomic) TBSDKPostFormat postFormat;
  44. @property (strong,nonatomic) NSMutableArray *fileData;
  45. @property (strong,nonatomic) NSHTTPURLResponse *response;
  46. @property (strong,nonatomic) NSMutableData *postBody;
  47. @property (atomic,assign) BOOL isFinished;
  48. @property (assign,nonatomic) BOOL unHostedByNetWork;
  49. // 打点判断是否是http
  50. @property (nonatomic, assign) BOOL isHttp;
  51. @property (nonatomic, strong) NSMutableArray *postData;
  52. @property (nonatomic, assign) int postGzipSize;
  53. // ut dataset dictionary
  54. @property (nonatomic, strong) NSDictionary *utDict;
  55. @property (nonatomic, assign) CFAbsoluteTime networkEndTime;
  56. // 新增统计打点error
  57. @property (nonatomic,strong) NSError *rawError;
  58. + (instancetype)requestWithURL:(NSURL *)newURL;
  59. + (void) cancelAll;
  60. - (instancetype)initWithURL:(NSURL *)newURL;
  61. - (void)setPostValue:(id<NSObject>)value forKey:(NSString *)key;
  62. - (void)addRequestHeader:(NSString *)header value:(NSString *)value;
  63. - (void)addCustomRequestHeader:(NSString *)header value:(NSString *)value; // 新增添加自定义请求头(通过该接口添加的请求头不做urlencode)
  64. - (void)startAsynchronous;
  65. - (void)startSynchronous;
  66. - (void)clearDelegatesAndCancel;
  67. - (void)addData:(id)data withFileName:(NSString *)fileName andContentType:(NSString *)contentType forKey:(NSString *)key;
  68. @end