Print NSMutableURLRequest Contents

后端 未结 2 1127
星月不相逢
星月不相逢 2021-02-13 03:49

I want to ask if anybody has ever tried printing out the values of a NSMutableURLRequest *request;

Here\'s my scenario, I have formed my XML and tried sending it using F

相关标签:
2条回答
  • 2021-02-13 04:19
    NSLog(@"Request body %@", [[NSString alloc] initWithData:[request HTTPBody] encoding:NSUTF8StringEncoding]);
    
    0 讨论(0)
  • 2021-02-13 04:20
    - (NSString *)formatURLRequest:(NSURLRequest *)request
    {
        NSMutableString *message = [NSMutableString stringWithString:@"---REQUEST------------------\n"];
        [message appendFormat:@"URL: %@\n",[request.URL description] ];
        [message appendFormat:@"METHOD: %@\n",[request HTTPMethod]];
        for (NSString *header in [request allHTTPHeaderFields])
        {
            [message appendFormat:@"%@: %@\n",header,[request valueForHTTPHeaderField:header]];
        }
        [message appendFormat:@"BODY: %@\n",[[NSString alloc] initWithData:[request HTTPBody] encoding:NSUTF8StringEncoding]];
        [message appendString:@"----------------------------\n"];
        return [NSString stringWithFormat:@"%@",message];
    }
    
    - (NSString *)formatURLResponse:(NSHTTPURLResponse *)response withData:(NSData *)data
    {
        NSString *responsestr = [[NSString alloc] initWithBytes:[data bytes] length:[data length] encoding:NSUTF8StringEncoding];
        NSMutableString *message = [NSMutableString stringWithString:@"---RESPONSE------------------\n"];
        [message appendFormat:@"URL: %@\n",[response.URL description] ];
        [message appendFormat:@"MIMEType: %@\n",response.MIMEType];
        [message appendFormat:@"Status Code: %ld\n",(long)response.statusCode];
        for (NSString *header in [[response allHeaderFields] allKeys])
        {
            [message appendFormat:@"%@: %@\n",header,[response allHeaderFields][header]];
        }
        [message appendFormat:@"Response Data: %@\n",responsestr];
        [message appendString:@"----------------------------\n"];
        return [NSString stringWithFormat:@"%@",message];
    }
    
    0 讨论(0)
提交回复
热议问题