nsurlsessiondatatask


AFHTTPSessionManager post request


I want to post a request to server. It is working fine if I am using NSURLSessionDataTask. But underneath I need to use AFNetworking as my whole application is using it. But when I am trying to hit the same service in AFHTTPSessionManager with POST method, It is giving me request time out.
Below are both the codes.
NSError *error;
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:nil delegateQueue:nil];
NSURL *url = [NSURL URLWithString:#"BASE URL"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
[request addValue:#"application/json" forHTTPHeaderField:#"Content-Type"];
[request addValue:#"application/json" forHTTPHeaderField:#"Accept"];
[request setHTTPMethod:#"POST"];
NSString *postString = #"1";
NSData *data = [postString dataUsingEncoding:NSUTF8StringEncoding];
[request setHTTPBody:data];
NSURLSessionDataTask *postDataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSString *str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
}];
[postDataTask resume];
AFNetworking kit version :-
AFHTTPSessionManager *client = [[AFHTTPSessionManager alloc] initWithBaseURL:[NSURL URLWithString:#"BASE URL"]];
NSDictionary *request = #{#"Content-Type":#"application/json",
#"Accept":#"application/json",
};
NSString *postString = #"1";
NSData *data = [postString dataUsingEncoding:NSUTF8StringEncoding];
[client POST:#"" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithHeaders:request body:data];
} success:^(NSURLSessionDataTask *task, id responseObject) {
NSLog(#"%#",responseObject);
} failure:^(NSURLSessionDataTask *task, NSError *error) {
NSLog(#"%#",error);
}];
Please help me in implementing it in right way.
I solved this problem by creating my own request and give its configuration to AFURLSessionManager and then holding my own NSURLSessionUploadTask object.
Thanks

Related Links

AFHTTPSessionManager post request
How to return a value with NSURLSessionDataTask? xcode

Categories

HOME
adal
devise
bitbucket-api
newrelic
xbee
cublas
rom
simulink
interpolation
webix
google-schemas
mel
alamofire
renjin
zerobrane
screen-readers
gruntfile
linear-algebra
jersey-1.0
shortest-path
nodemcu
string-concatenation
dynamically-generated
android-sharedpreferences
winexe
gp
carrierwave
failover
record
linkedhashmap
activexobject
vue-chartjs
reactjs.net
sharding
nested-lists
html-encode
batching
video-capture
android-augmented-reality
hackintosh
softmax
xmldocument
clang++
rfc3339
ntvs
yii2-api
twilio-click-to-call
excel-dna
janus
file-uri
watch-os-2
greatest-n-per-group
hclust
simevents
appscale
database-relations
mobiledoc-kit
user-management
crouton-os
concurrentmodification
django-urls
fuelcms
liquid-layout
teamcity-9.1
android-vibration
nsmenu
jama
ora-00904
tinyxml
radiant
decoupling
dsym
websphere-esb
script#
gpars
traceability
onload-event
mantle
joomla3.1
jquery-blockui
paginator
extconf.rb
ikimagebrowserview
filemerge
strsep
strtod
data-mapping
dsl-tools
interop-domino

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App