美文网首页
集成YTKNetwork 更改Content-Type

集成YTKNetwork 更改Content-Type

作者: 善良的皮蛋 | 来源:发表于2020-07-29 16:08 被阅读0次
- (NSURLRequest *)buildCustomUrlRequest
{
    // 服务器地址
    NSMutableString *urlString = [[NSMutableString alloc] initWithString:[NSString stringWithFormat:@"%@%@",[YTKNetworkConfig sharedConfig].baseUrl,self.requestReServiceType]];
    NSURL *URL=[NSURL URLWithString:urlString];
    NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:URL];
    request.HTTPMethod=@"POST";
    [request addValue:@"application/json;charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:self.reParams options:NSJSONWritingPrettyPrinted error:nil];

    request.HTTPBody= jsonData;
    NNHLog(@"\n\n**************!!  组成Post请求体  !!**********************\n\n\
                   ApiName:%@\n \n\
                 RequestBody : %@\n\n  APIURL:%@ \n\n ******************!!  End  !!************************\n   ", self.reAPIName,self.reParams,urlString);
    
    
    return request;
}
- (NSURLRequest *)buildCustomUrlRequest
{
    // 服务器地址
    NSMutableString *muString = [NSMutableString string];
    /**  开始拼接参数  */
    [muString appendString:@"?"];
    for (NSString *key in self.reParams) {
        [muString appendFormat:@"%@=%@&", key, [self.reParams objectForKey:key]];
    }
    
    // 服务器地址
    NSMutableString *urlString = [[NSMutableString alloc] initWithString:[NSString stringWithFormat:@"%@%@%@",[YTKNetworkConfig sharedConfig].baseUrl,self.requestReServiceType,muString]];
    
    
    NSURL *URL=[NSURL URLWithString:urlString];
    NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:URL];
    request.HTTPMethod=@"GET";
   [request addValue:@"application/json;charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
    NNHLog(@"\n\n**************!!  组成Get请求体  !!**********************\n\n\
                   ApiName:%@\n \n\
                 RequestBody : %@\n\n  APIURL:%@ \n\n ******************!!  End  !!************************\n   ", self.reAPIName,self.reParams,urlString);
    
    
    return request;
}

========================

后续再补充

相关文章

网友评论

      本文标题:集成YTKNetwork 更改Content-Type

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