java - How to connect localwebserver from iPhone app -
i have made implementation of localhosted webserver works fine . webserver expososes ejb interface clients can connect , make calls . created java client connects ejb interface , calls exposed api's . webserver accepts json object , can parse send json response . works fine , 100% java (which know).
now need create iphone app client for/ connect webserver , calls exposed apis , exchange json objects . since very new not sure how work within iphone app . how shld connect webserver . hosted localally on system .
so question : how connect webserver exchange json objects ? searched on couldnt find .
there simple ways connect server ios app. can using nsurlrequest or nsurlconnection. simple understand , implement.
apple docs on connecting using http , https.
nsurlconnection tutorial (contains multiple methods in class).
using these can establish connection server , make requests.
now, since did mention json, there class called jsonhttpclient. have used success several times fetch , parse json. here useful tutorial can started.
another option work using datawithcontentsofurl:options:error: nsdata class. somthing like:
nsdata * data = [nsdata datawithcontentsofurl: [nsurl urlwithstring:@"yoururlhere.com"]];
if url returns json, can download , parse using
[nsjsonserialization jsonobjectwithdata:data options:kniloptions error:&error];
Comments
Post a Comment