Closed paresh-navadiya closed 9 years ago
Does it work with STHTTPRequest 1?
No its not working in STHTTPRequest 1 as its throwing same error
Error Domain=STHTTPRequest Code=400 "HTTP Status 400: Bad Request" UserInfo={NSLocalizedDescription=HTTP Status 400: Bad Request}
Solved by making necessary changes like say by adding a new method which accepts NSURLRequest :
+ (instancetype)requestWithURLRequest:(NSURLRequest *)urlRequest;
Method defination and also supplementary method added for requirement:
+ (instancetype)requestWithURLRequest:(NSURLRequest *)urlRequest {
if(urlRequest == nil) return nil;
return [(STHTTPRequest *)[self alloc] initWithURLRequest:urlRequest];
}
- (instancetype)initWithURLRequest:(NSURLRequest *)theURLRequest {
if (self = [super init]) {
self.request = theURLRequest;
self.url = theURLRequest.URL;
self.responseData = [[NSMutableData alloc] init];
self.requestHeaders = [NSMutableDictionary dictionary];
self.POSTDataEncoding = NSUTF8StringEncoding;
self.encodePOSTDictionary = YES;
self.encodeGETDictionary = YES;
self.addCredentialsToURL = NO;
self.timeoutSeconds = kSTHTTPRequestDefaultTimeout;
self.filesToUpload = [NSMutableArray array];
self.dataToUpload = [NSMutableArray array];
self.HTTPMethod = theURLRequest.HTTPMethod; // default : GET
self.cookieStoragePolicyForInstance = STHTTPRequestCookiesStorageUndefined; // globalCookiesStoragePolicy will be used
self.ephemeralRequestCookies = [NSMutableArray array];
}
return self;
}
Changes in startAsynchronous method :
- (void)startAsynchronous {
NSAssert((self.completionBlock || self.completionDataBlock), @"a completion block is mandatory");
NSAssert(self.errorBlock, @"the error block is mandatory");
if (!self.request)
self.request = [self prepareURLRequest];
BOOL useUploadTaskInBackground = [self.request.HTTPMethod isEqualToString:@"POST"] && self.request.HTTPBody != nil;
------ After above changes make changes for request instance --------
------------------------------------------
-------------------------------------------
}
The correct format is:
STHTTPRequest *request = [STHTTPRequest requestWithURLString:@"http://w3schools.com/webservices/tempconvert.asmx"];
[request setHeaderWithName:@"SOAPAction" value:@"http://www.w3schools.com/webservices/CelsiusToFahrenheit"];
request.rawPOSTData = soapData;
request.completionBlock = ^(NSDictionary *headers, NSString *body) {
NSLog(@"headers = %@\nbody = %@", headers, body);
};
request.errorBlock = ^(NSError *error) {
NSLog(@"%@",[error description]);
};
[request startAsynchronous];
I have native request like this :
Now request using STHTTPRequest2 that i tried and was not successfull.