Online This three class library is about to see vomit, swifthttp,yyhrquest,afnetworking;http request is nothing more than call these class library of put,get,post,delete, which need our brains is probably the parameter of the pass,
A: Put and delete, the same way, directly behind the URL stitching ¶meter on it, such as Http://10.111.11.11:8088/api/?sqlname=GET_ALL&name=dog &password=123
You can, of course, use the dictionary provided by the class library to put parameters
When using the Swifthttp
var request = Httptask () var parameters:dictionary<string,string>=["name": "Dog", "password": "123"]request . GET ("Http://10.111.11.11:8088/api/?sql=GET_ALL", Parameters:nil, Success: {(response:httpresponse), Void in If Response.responseobject! = Nil {println ("Success")}},failure: {(Error:nserror, _), Void in println ("false")})
</pre><pre>
Two: What about post and put? What if the server does not recognize the word typical? (Oh, what a fuck day)
All I can say is a quiet conversion.
<pre name= "code" class= "OBJC" > Public func POST (url:string, parameters:dictionary<string,anyobject>, Success: ((HttpResponse)-void)!, failure: ((Nserror, HttpResponse?), void)!) { //var opt = var opt = self.create (URL, method:. POST, parameters:parameters,success:success,failure:failure) if opt! = nil { opt!. Start () } }
This is swifthttp in the post way, look good, but this word typical parameter server does not know him as long as the JSON type, OK, the mountain does not turn the water turn, the water does not turn the person, I do not need this
Three: I want to use yyhrequest this class library to try, (looks good cottage name, but the advantage is you can transform him)
Func post (strpara:[string],strusername:string,strpassword:string) {let request = Yyhrequest (Url:nsurl (String: " Http://10.11.11.1:8088/api/?sql=UPDATE1 " var parameterstr:string =" "Request.method =" POST " // The following is a demo, and then there is no egg, the server or do not know request.parameters["name"] = "dog" request.parameters["password"] = " 123 "//So write server really know, just think this is JSON, I am also drunk parameterstr=" {' Name ': ' Dog ', ' password ': ' 123 '} " request.parameters[" " ] = Parameterstr Request.completionhandler = {response, data, error in } request.loadrequest () }
Well, after the use of the above post can finally plug into the database, haha, this parameter is too simple, I also think, to a nested, good, you see the next period!
What does the SWIFT server require for JSON objects? A