我想使用swift HTTP Entity
添加NSURLConnection
(W3.org link)。
我在Http Header
中添加了entity-body
urlEncoded
NSMutableURLRequest
个var request:NSMutableURLRequest = NSMutableURLRequest(URL:URL)
request.HTTPMethod = "POST"
request.setValue("{ my JSON Data }", forHTTPHeaderField: "entity-body")
个键值,但无效!
修改
Content-Security-Policy
答案 0 :(得分:2)
最后,我找到了一个有效的答案!
object是我的JSON,存储在swift String中。
var request:NSMutableURLRequest = NSMutableURLRequest(URL:URL)
request.setValue(String(count(object)), forHTTPHeaderField: "Content-Length");
request.HTTPBody = object.dataUsingEncoding(NSUTF8StringEncoding);