I am writing the swift code to send a http post request to the php server. But my php script always get the strange post body because the parameters are wrapped by the Option(), If I send parameters like "id=john&password=1234", the server will get Optional(id=john&password=1234). But this is not what I want because php cannot analyse the parameters in the normal way. I have no idea about what's going wrong here;
var postString: String = "id=john&password=1111"
request.HTTPBody = (postString.dataUsingEncoding(NSUTF8StringEncoding))
println("Body will send: \(request.HTTPBody)")
var postLength:NSString = String( postString2.dataUsingEncoding(NSUTF8StringEncoding)!.length )
request.setValue(postLength, forHTTPHeaderField: "Content-Length")
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
request.setValue("multipart/form-data", forHTTPHeaderField: "Accept")
After the above preparing code, I use dataTaskWithRequest method to send the post. After google this question for several days, I am going crazy about this unsolved problem. Need a clue to fix it. Please advise!