I tried all the way, but getting error
NSLocalizedDescription=Request failed: bad request (400), com.alamofire.serialization.response.error.data=<48545450 20343030 0a4d6973 73696e67 20706172 616d6574 65723a20 27726566 6572656e 636527>, NSUnderlyingError=0x7a81aa80 {Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/plain" UserInfo={com.alamofire.serialization.response.error.response= { URL: https:///mobile/v1/document/get } { status code: 400, headers { "Cache-Control" = "no-cache, private"; Connection = "keep-alive"; "Content-Type" = "text/plain; charset=UTF-8"; Date = "Sun, 29 May 2016 20:31:44 GMT"; Server = "nginx/1.4.6 (Ubuntu)"; "Strict-Transport-Security" = "max-age=2592000; includeSubDomains"; "Transfer-Encoding" = Identity; "X-Exception-Class" = "PM\PFTAPIBundle\Exception\MissingAPIParameterException"; "X-Exception-Message" = "Missing parameter: 'reference'"; "X-Frame-Options" = SAMEORIGIN; "X-Processing-Time" = "906.5ms"; } }, NSErrorFailingURLKey=https:///api/mobile/v1/document/get, NSLocalizedDescription=Request failed: unacceptable content-type: text/plain, com.alamofire.serialization.response.error.data=<48545450 20343030 0a4d6973 73696e67 20706172 616d6574 65723a20 27726566 6572656e 636527>}}} Request failed: bad request (400)
- (void)postResource:(NSString*)resource queryString:(NSDictionary*)queryString withCompletionHander:(CompletionHandlerBlock)completionHandler
{
NSString *qs = [DictionaryUtils convertDictToJSONString:queryString];
// self.sessionManager.requestSerializer = [AFJSONRequestSerializer serializer];
// self.sessionManager.responseSerializer = [AFJSONResponseSerializer serializer];//[AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingAllowFragments];
// [self.sessionManager.requestSerializer setValue:[NSString stringWithFormat:@"PLSID %@",sessionID] forHTTPHeaderField:@"Authorization"];
resource = [[self.sessionManager.baseURL URLByAppendingPathComponent:@"document/get"] absoluteString];
NSURL *base = [NSURL URLWithString:resource];
NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:base
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:60.0];
[theRequest setHTTPMethod:@"POST"];
[theRequest setValue:mACCEPTVALUE forHTTPHeaderField:mCONTENTTYPELABEL];
if ([[[UserDetails sharedInstance]getUserDetails]objectForKey:mSESSIONIDKEY]) {
NSString *headerField = [NSString stringWithFormat:@"%@ %@",mSOURCEPLSID,sessionID];
[theRequest setValue:headerField forHTTPHeaderField:mSOURCEIDENTIFIERHEADER];
}
if(qs != nil) {
[theRequest setHTTPBody:[qs dataUsingEncoding:NSUTF8StringEncoding]];
}
NSURLSessionDataTask *dataTask = [self.sessionManager dataTaskWithRequest:theRequest completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
//
NSLog(@"responseObject %@", responseObject);
NSLog(@"%@ \n%@",error, [error localizedDescription]); //{Error Domain=kCFErrorDomainCFNetwork Code=-1005 "(null)" UserInfo={_kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-4}}}
}];
[dataTask resume];
}
When I test the api using postman and passing the param in Body
as raw data {"reference":{"Id":"User","documentId":"56e0"}}
[NOTE: NOT in x-www-form-urlencoded or form-data]. It works and getting response with data.
text/json
, because the error you posted clearly shows that it isn't. – AviHTTP 400 Missing parameter: 'reference'
. – Avi