ios


How to set NSInteger in HTTPHeaderField in AFnetworking


I want to set NSInteger value in HTTPHeaderField. Below is my code
NSInteger user_id =1234;
if ([AFNetworkReachabilityManager sharedManager].reachable) {
AFHTTPRequestOperationManager *afRequestOpManager = [AFHTTPRequestOperationManager manager];
afRequestOpManager.requestSerializer = [AFJSONRequestSerializer serializer];
afRequestOpManager.responseSerializer = [AFJSONResponseSerializer serializer];
[afRequestOpManager.requestSerializer setValue:user_id forHTTPHeaderField:#"user-id"];
[afRequestOpManager PUT:strUrl parameters:nil success: ^(AFHTTPRequestOperation *operation, id responseObject)
{
NSLog(#"JSON: %#", responseObject);
}failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(#"JSON: %ld", error.code);
}];
But i am not able to set user_id as integer.
The type which is passed into setValue: is NSString. In order to convert your NSInteger to NSString, use this: [NSString stringWithFormat:#"%ld", (long)user_id]
The HTTP Headers values can only take string values, it cannot have any other data type values,
So convert your user id to string as below
[NSString stringWithFormat:#"%d",user_id]
Then set the Value in the headers , also just for convention , always prefix your custom http headers with X- so ur header will become X-user-id

Related Links

App Store Shows English UK Screenshot Instead of my English US Screen Shot
Running appium on iOS device with tests on a Windows machine
Why is PHImageRequestOptions.progressHandler never called?
GMSMarker - custom alert/pop-up not using markerInfoWindow
react-native ios project + memory leak
Parsing Error using RestKit : Loaded an unprocessable response (200) with content type 'application/json'
The webview doesn't Display url
Spacing between UITableViews like Settings Application
Google font does not work in IOS system, such as iPad and iPhone
Json Code is not working
How to solve keyboard problems in Swift 3?
How can I customize the scrolling path of a uicollectionview?
preinstalled iOS apps in other languages
inputAccessoryViewController height modification
What could be “advanced” settings in developers.facebook.com/apps/settings/Hybrid Mobile App - android and iOS for Production
How to remotely access a local parse server (parse port and server url)

Categories

HOME
math
embedded-linux
demandware
opencl
coffeescript
x-editable
robotframework
watson
chronicle
xamarin.forms-listview
feed
mocha
stripe-payments
jasypt
webdriver-io
sony-camera-api
drag
calayer
threadpool
command-line-arguments
sonata-admin
axios
partitioning
w2ui
durandal-2.0
formio
teamcity-9.0
media-source
google-finance
slime
beanstalkd
windows-applications
line-breaks
mouseevent
ssms-2014
weather-api
physics
rrd
angular-ngmodel
valueinjecter
evercookie
django-users
dlopen
codeskulptor
jformattedtextfield
google-crawlers
sieve-of-eratosthenes
texture-mapping
protobuf-3
message-hub
firedac
subscription
textangular
couchbase-lite
maven-jetty-plugin
php-deployer
oracle-aq
adal.js
spring-form
jce
webloadui
catalina
android-touch-event
postmark
agile-processes
itamae
ocsp
xnamespace
benerator
jquery-load
google-api-ruby-client
ctakes
screen-capture
genetic
pypdf
ubiquity
avalonedit
realm-list
devenv
gem5
byte-order-mark
wintersmith
openxls
javaw
android-design-library
isql
culture
symfony-2.5
citymaps
dynamic-typing
directcompute
tinkerpop-frames
data-quality
magento-1.6
hebrew
css3pie
showcaseview
ioerror
pligg
semantic-markup
polarssl
pubdate
webcal
asp.net-authentication
ariatemplates
ad-hoc-distribution
android-actionmode
cellphone
livevalidation
system-tray
anemic-domain-model
eclipse-tptp
shareware
usenet

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App