AFHTTPSessionManager 问题
AFHTTPSessionManager issue
我正在使用 Afnetworking Framework,但每次我访问网络服务时,响应总是如下所示-
错误域=com.alamofire.error.serialization.response代码=-1011"Request failed: unauthorized (401)"用户信息={com.alamofire.serialization.response.error.response
并且我已经使用了下面的代码 谁能帮助我-
NSString * finalUlr = [kMainUrl stringByAppendingString:url];
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
[manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[manager.requestSerializer setValue:@"1f76f057-1809-0bfd-5b53-f2f6c2d3ab81" forHTTPHeaderField:@"postman-token"];
[manager.requestSerializer setValue:@"qW9Bf_-RxXFz8mtxDqUYYzBN2V9N6he_tOTbSgJskVA" forHTTPHeaderField:@"x-csrf-token"];
[manager POST:finalUlr parameters:Patameters progress:nil success:^(NSURLSessionTask *task, id responseObject) {
NSLog(@"JSON: Success");
completionBlock(YES,responseObject);
} failure:^(NSURLSessionTask *operation, NSError *error) {
NSLog(@"Error: %@", error);
completionBlock(NO,nil);
}];
试试这个
NSString * finalUlr = [kMainUrl stringByAppendingString:url];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:finalUlr] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10];
[request setHTTPMethod:GET_METHOD]; // or POST_METHOD
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"1f76f057-1809-0bfd-5b53-f2f6c2d3ab81" forHTTPHeaderField:@"postman-token"];
[request setValue:@"qW9Bf_-RxXFz8mtxDqUYYzBN2V9N6he_tOTbSgJskVA" forHTTPHeaderField:@"x-csrf-token"];
AFHTTPRequestOperation *op = [[AFHTTPRequestOperation alloc] initWithRequest:request];
op.responseSerializer = [AFJSONResponseSerializer serializer];
[op setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject)
{
if (responseObject)
{
}
else
{
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error){
}];
[op start];
希望这对您有所帮助
希望对你有用..
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
[manager POST:str6 parameters:@{} progress:nil success:^(NSURLSessionTask *task , id responseObject)
{
NSLog(@"%@",responseObject);
}failure:^(NSURLSessionTask *operation ,NSError *error)
{
}];
注:-
1)在 str6 中使用您的 url.
2)在参数中使用你的参数。
你可以像这样传递参数...
NSDictionary *dict =[[NSDictionary alloc]initWithObjectsAndKeys:strEmail,@"email",strPassword,@"password",uniqueIdentifier,@"session_id", nil];
这里的 strEmail 是你的值等等..
@"email" 是你的钥匙等等..
我正在使用 Afnetworking Framework,但每次我访问网络服务时,响应总是如下所示-
错误域=com.alamofire.error.serialization.response代码=-1011"Request failed: unauthorized (401)"用户信息={com.alamofire.serialization.response.error.response
并且我已经使用了下面的代码 谁能帮助我-
NSString * finalUlr = [kMainUrl stringByAppendingString:url];
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
[manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[manager.requestSerializer setValue:@"1f76f057-1809-0bfd-5b53-f2f6c2d3ab81" forHTTPHeaderField:@"postman-token"];
[manager.requestSerializer setValue:@"qW9Bf_-RxXFz8mtxDqUYYzBN2V9N6he_tOTbSgJskVA" forHTTPHeaderField:@"x-csrf-token"];
[manager POST:finalUlr parameters:Patameters progress:nil success:^(NSURLSessionTask *task, id responseObject) {
NSLog(@"JSON: Success");
completionBlock(YES,responseObject);
} failure:^(NSURLSessionTask *operation, NSError *error) {
NSLog(@"Error: %@", error);
completionBlock(NO,nil);
}];
试试这个
NSString * finalUlr = [kMainUrl stringByAppendingString:url];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:finalUlr] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10];
[request setHTTPMethod:GET_METHOD]; // or POST_METHOD
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"1f76f057-1809-0bfd-5b53-f2f6c2d3ab81" forHTTPHeaderField:@"postman-token"];
[request setValue:@"qW9Bf_-RxXFz8mtxDqUYYzBN2V9N6he_tOTbSgJskVA" forHTTPHeaderField:@"x-csrf-token"];
AFHTTPRequestOperation *op = [[AFHTTPRequestOperation alloc] initWithRequest:request];
op.responseSerializer = [AFJSONResponseSerializer serializer];
[op setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject)
{
if (responseObject)
{
}
else
{
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error){
}];
[op start];
希望这对您有所帮助
希望对你有用..
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
[manager POST:str6 parameters:@{} progress:nil success:^(NSURLSessionTask *task , id responseObject)
{
NSLog(@"%@",responseObject);
}failure:^(NSURLSessionTask *operation ,NSError *error)
{
}];
注:-
1)在 str6 中使用您的 url.
2)在参数中使用你的参数。
你可以像这样传递参数...
NSDictionary *dict =[[NSDictionary alloc]initWithObjectsAndKeys:strEmail,@"email",strPassword,@"password",uniqueIdentifier,@"session_id", nil];
这里的 strEmail 是你的值等等..
@"email" 是你的钥匙等等..