Alamofire3.0 Brief Introduction

Source: Internet
Author: User

Built-in response function
    • Response ()
    • ResponseData ()
    • Responsestring (encoding:nsstringencoding)
    • Responsejson (options:nsjsonreadingoptions)
    • Responsepropertylist (options:nspropertylistreadoptions)

Example

Responsestring:

inch             Print ("Success: \ (response.result.isSuccess)")            print (  "Response String: \ (response.result.value)")        }

Output:

// true Response string:optional ("(b5drrjuy4yjj1j45jc5w1f45)")

Response

inch             Print (Request) print (            response) print (            error)        }

Output:

//Optional (<nsmutableurlrequest:0x7fdd9a5d3db0> {url:http://www.example.com})Optional (<nshttpurlresponse:0x7fdd9a5a2490> {url:http://www.example.com} {status code:200, headers {Connection ="keep-alive"; "content-encoding"=gzip; "Content-type"="text/html"; Date="Wed, 08:11:00 GMT"; Server=Nginx; "transfer-encoding"=Identity; Via="1.1.1.1";} }) Optional (<28323161 76733466716b766170726135 35697578646c72627729>) Nil

ResponseData:

inch                 Print (response.request)                print (response.response)                print (Response.result)        }

Output:

//Optional (<nsmutableurlrequest:0x7fc15b83f930> {url:http://www.example.com})Optional (<nshttpurlresponse:0x7fc1597038c0> {url:http://www.example.com} {status code:200, headers {Connection ="keep-alive"; "content-encoding"=gzip; "Content-type"="text/html"; Date="Wed, 08:14:33 GMT"; Server=Nginx; "transfer-encoding"=Identity; Via="1.1.1.1";} }) SUCCESS

Responsejson:

inch                 DebugPrint (response)        }

Output:

[Request]: <nsmutableurlrequest:0x7ff8e0e2ceb0> {url:http://1.jwxtapi.applinzi.com/getidstring.php}[Response]: <nshttpurlresponse:0x7ff8e0e67150> {url:http://1.jwxtapi.applinzi.com/getidstring.php} {Status code:200, headers {Connection ="keep-alive"; "content-encoding"=gzip; "Content-type"="text/html"; Date="Wed, 08:15:38 GMT"; Server=Nginx; "transfer-encoding"=Identity; Via="1.1.1.1";} }[data]: -Bytes[result]: failure:error Domain=nscocoaerrordomain code=3840 "Invalid value around character 0."Userinfo={nsdebugdescription=invalid value around character0.} [Timeline]: Timeline: {"Request Start time":478599338.905915,"Initial Response time":478599339.333833,"Request completed time":478599339.334189,"Serialization completed time":478599339.334308,"Latency":0.427917957305908secs"Request Duration":0.428273975849152secs"Serialization Duration":0.000119030475616455secs"Total Duration":0.428393006324768secs}
Alamofire.request (. GET, url). Responsejson {Responseinchprint (response.request)//Original URL RequestPrint (Response.response)//URL ResponsePrint (Response.data)//Server DataPrint (Response.result)//result of response serialization                        ifLet JSON =response.result.value {print ("JSON: \ (JSON)")            }        }

Output:

Optional (<nsmutableurlrequest:0x7fd69bf57ff0> {url:http://www.example.com })Optional (<nshttpurlresponse:0x7fd69bc1dcc0> {url:http://www.example.com} {Status code:200, headers {Connection ="keep-alive"; "content-encoding"=gzip; "Content-type"="text/html"; Date="Wed, 08:17:54 GMT"; Server=Nginx; "transfer-encoding"=Identity; Via="1.1.1.1";} }) Optional (<286473776e617835 3531636b70327171 33326134 35653434 3529>) FAILURE

Alamofire3.0 Brief Introduction

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.