美文网首页
iOS-调试接口以及postman

iOS-调试接口以及postman

作者: 守护地中海的花 | 来源:发表于2020-08-08 13:31 被阅读0次
http://192.168.0.175:8888/v1/business/app/seller/getSellerInfo
{"sellerId":"1"}

后台给的截图 好多参数 其实不需要的 如图

121596857737_.pic_hd.jpg

我自己调试postMan截图


image.png image.png image.png

设置代码

if ([UserManager logined]) {
    //设置这样可以
    [PPNetworkHelper setRequestSerializer:PPRequestSerializerJSON];
    [PPNetworkHelper setResponseSerializer:PPResponseSerializerJSON];
    
    //设置这样也可以
    //_sessionManager.requestSerializer = [AFJSONRequestSerializer serializer];
    //_sessionManager.responseSerializer = [AFJSONResponseSerializer serializer];
    
    //光设置这些没屌用
    //[_sessionManager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    //[_sessionManager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    
    [_sessionManager.requestSerializer setValue:sharedUserManager.account.token forHTTPHeaderField:@"token"];
}

设置服务器状态code

NSURLSessionDataTask * _Nonnull task

NSURLResponse *responseZt = [task response];
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)responseZt;
NSInteger responseCode = [httpResponse statusCode];

faliure

//如果域名错误 errorResponse 是空的 false 也是@“” length长度 0
NSString* errorResponse = [[NSString alloc] initWithData:(NSData *)error.userInfo[@"com.alamofire.serialization.response.error.data"] encoding:NSUTF8StringEncoding];
NSMutableDictionary *errorDic;
if (errorResponse && ![errorResponse isEqualToString:@""]) {
    NSData *jsonData = [errorResponse dataUsingEncoding:NSUTF8StringEncoding];
    NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:jsonData options:kNilOptions error:NULL];
    errorDic = [dict mutableCopy];
    [errorDic setValue:[NSNumber numberWithInteger:[httpResponse statusCode]] forKey:@"status_code"];
    [errorDic setValue:@"资源不存在" forKey:@"message"];
    [errorDic setValue:@"0" forKey:@"success"];
    [errorDic setValue:@"10001" forKey:@"code"];
} else {
    errorDic = [NSMutableDictionary dictionary];
    [errorDic setValue:[NSNumber numberWithInteger:[httpResponse statusCode]] forKey:@"status_code"];
    [errorDic setValue:@"资源不存在" forKey:@"message"];
    [errorDic setValue:@"0" forKey:@"success"];
    [errorDic setValue:@"10001" forKey:@"code"];
}

相关文章

网友评论

      本文标题:iOS-调试接口以及postman

      本文链接:https://www.haomeiwen.com/subject/utkhdktx.html