How to send POST parameters in Swift?

前端 未结 4 1395
花落未央
花落未央 2020-12-23 14:46

Here some code:

var URL: NSURL = NSURL(string: \"http://stackoverflow.com\")
var request:NSMutableURLRequest = NSMutableURLRequest(URL:URL)
request.HTTPMetho         


        
4条回答
  •  Happy的楠姐
    2020-12-23 15:13

    No different than in Objective-C, HTTPBody expects an NSData object:

    var bodyData = "key1=value&key2=value&key3=value"
    request.HTTPBody = bodyData.dataUsingEncoding(NSUTF8StringEncoding);
    

    You'll have to setup the values & keys yourself in the string.

提交回复
热议问题