Objective C - HttpRequest with Daemon -


i have created daemon in objective c after search usb device, have send httprequest url.

i have tried browser , host reachable.

for create daemon have used foundation framework , this, have tried create http request way:

nsurlrequest *eventrequest = [nsurlrequest requestwithurl:_urlrequest cachepolicy:nsurlrequestuseprotocolcachepolicy timeoutinterval:20];  self.theconnection=[[nsurlconnection alloc] initwithrequest:eventrequest delegate:self];  if (self.theconnection) {     self.receiveddata = [[nsmutabledata data] retain]; } else {     // inform user connection failed.     nslog(@"connection problem"); } 

but in case have 2 problems:

  1. the request not send.
  2. the daemon ends , doesn't wait response of httprequest.

how can solve problem? exist way make http request , response?

regards.

many people find afnetworking framework (git clone https://github.com/afnetworking/afnetworking) makes http interactions easier.

specifically, afnetworking getpath: , postpath: methods accept path, parameters dictionary, , 2 blocks, 1 success , 1 failure. such

{ [self getpath: @"users"      parameters: @{ @"api_key" : @"appapikeyforserver" }         success: ^(afhttprequestoperation *operation, nsdictionary *json) {           nsarray *users = json[@"users"];           ....         }         failure: ...]; } 

creating afnetworking clients easy well. can create simple http client or oauth2 client:

@interface myclient : afoauth2client @end  - (myclient *) init {   if (self = [super initwithbaseurl: [nsurl urlwithstring: kmyclientapibaseurlstring]                            clientid: kmyclientoauth2clientid                              secret: kmyclientoauth2clientsecret])   {     [self registerhttpoperationclass: [afjsonrequestoperation class]];     [self setdefaultheader: @"accept"                      value: @"application/json"];   }   return self; } 

as daemon need. should able have daemon retain pointer afnetworking client , make repeated requests.

note oauth2 client found @ https://github.com/afnetworking/afoauth2client


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -