我如下代码发送请求,为什么在服务其上。用request.getParamter("name")
那不到值呢?
TTURLRequest *request = [self request:url Delegate:delegate]; [request setHttpMethod:@"POST"]; [request.parameters setObject:@"agassi_yzh" forKey:@"name"]; [request send];
大家讲道理2017-04-17 11:00:06
自己把问题解决了:
TTURLRequest的parameters中的数据设置的格式是发送文件的报文形式。
如果要用request.getParamter来解析。需要自己构造post的httpbody
这么写:
TTURLRequest *request = [self request:url Delegate:delegate]; [request setHttpMethod:@"POST"]; request.contentType=@"application/x-www-form-urlencoded"; NSMutableString* postBodyString = [NSMutableString stringWithString:@""]; if (nil != info) { [request setUserInfo:[NSDictionary dictionaryWithDictionary:info]]; } if (nil != params) { for (NSString *key in [params allKeys]) { NSString* p = [NSString stringWithFormat:@"%@=%@",key,[[params valueForKey:key] URLEncodedString]]; postBodyString = [NSString stringWithFormat:@"%@&%@",postBodyString,p]; } } NSData* postData = [NSData dataWithBytes:[postBodyString UTF8String] length:[postBodyString length]]; [request setHttpBody:postData]; [request send];