我发送Alamofire的HTTP请求,但服务器无法接收post参数。
let netParams = NetParams()
let ramdomStr = netParams.get16Strings()
let timeStamp = netParams.genTimeStamp()
let signDic:Dictionary<String,String> = ["version":"ios","timestamp":timeStamp!,"nonce":ramdomStr!,"event":"sngfcinformation"]
let sign = netParams.genSign(signDic)
//var obj = AseEncry()
let enStr = AseEncry .aseEn(withPlant: sign, andSecret: secretStr)
let params:Dictionary<String,String> = ["version":"ios","timestamp":timeStamp!,"nonce":ramdomStr!,"event":"sngfcinformation","sign":enStr!]
var returnDic:Dictionary<String,AnyObject> = ["a":"b" as AnyObject]
Alamofire.request(sngfcURL+"news/index.action", method: .post, parameters:params, encoding: JSONEncoding.default)
.responseJSON { response in
debugPrint("jsonhead")
debugPrint(response.result.value ?? AnyClass.self)
debugPrint("jsonend")
if let JSON = response.result.value {
returnDic = JSON as! Dictionary<String, AnyObject>
// block(dic:returnDic)
}
}
.responseString { (response) in
debugPrint("head")
debugPrint(response.result.value!)
debugPrint("end")
}
服务器可以回复我,但不能接收任何游侠。 然后我使用AFNetWoring,它运行良好,服务器获得正确的参数。
+(void)XYNetWorkWithParams:(NSDictionary*)dics withUrl:(NSString*)url withSuccessBlock:(backBlock)successBlock withfailBlock:(backBlock)failBlock{
AFHTTPRequestOperationManager *mgr=[AFHTTPRequestOperationManager manager];
NSString *netaddress=[NSString stringWithFormat:@"http://61.152.245.216/sngfc.mobile/news/index.action?"];
[mgr POST:netaddress parameters:dics success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSDictionary *dic = responseObject;
successBlock(dic);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
failBlock([NSDictionary dictionaryWithObjectsAndKeys:@"fail",@"msg", nil]);
}];
}
当我使用Alamofire时出了什么问题?