Web Service network communication for clients and servers in IOS

Source: Internet
Author: User
Tags representational state transfer

When you open the Sina Weibo app on your phone or the app is, do you think about where these images and data appear on your phone? What is the way to achieve it? Well, then the next introduction is how to achieve, and how the process.

when we look at the attention or friends of Weibo, those images and data is not out of thin air, but through your client to the server after the Sina Weibo server returned to the local to obtain, through the analysis of the data can be displayed on the client, or even operation. And these are the Web Service that we usually call . Web Service technology is a kind of service through Web protocol, which ensures that the application services of different platforms can interoperate and provide different services for client application. There are currently three main Web Service technologies: REST, SOAP, and Xml-rpc. Now the main introduction is the REST Web Service.

REST is translated as "representational State transfer", "characterization" is the page that the client sees, and the page jump is the transition of the State, and the client obtains the page to be displayed by requesting the URI. REST is typically based on these existing protocols and standards, such as HTTP, URI, and XML, as well as HTML.

The rest Web Service is a Web service that uses HTTP and follows the REST principle. Requests that the Web Service use the URI to locate the resource. The data Interchange format with Web Service is very flexible using JSON and XML. The HTTP request method supported by the Web Service, including POST, GET, put, or delete.

synchronize the request implemented by the GET method:

The previous article about JSON is local parsing, and now it's time to parse from the server request back data, and then look at the main methods of Web Service requests.

-(void) startrequest{        nsstring *strurl = [[NSString alloc] Initwithformat:                        @ "requested server address"];    Nsurl *url = [Nsurl urlwithstring:[strurl urlencodedstring]; Nsurlrequest *request = [[Nsurlrequest alloc] initwithurl:url];            NSData *data  = [nsurlconnection sendsynchronousrequest:request returningresponse:nil Error:nil];    NSLog (@ "request complete ...");    Nsdictionary *resdict = [nsjsonserialization jsonobjectwithdata:data options:nsjsonreadingallowfragments Error:nil];    [Self reloadview:resdict];    }
Initwithformat: method Specifies the requested URL, which is the Web Service that the URL points to. The next line of code is to use the strURL string above to create the Nsurl object, the argument is [strURL Urlencodedstring],strurl string and calls the Urlencodedstring method to convert the string to a URL string, in Intern When the ET is transmitted, no special characters such as Chinese can appear in the URL. Using this method is to convert these characters to the URL encoding with a percent sign (the URL encoding for the "<" symbol is "%3c").



Web Service network communication for clients and servers in IOS

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.