NSURLRequest to NSString

前端 未结 5 1842
渐次进展
渐次进展 2021-02-19 01:03

how can i convert NSURLRequest to NSString ?

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-19 01:37

    NSURLRequest *urlRequest;
    ...
    NSLog(@"%@", [urlRequest allHTTPHeaderFields]);
    NSLog(@"%@",[urlRequest valueForHTTPHeaderField:field]);
    

    In this example, urlRequest is an NSURLrequest (from the previous example above). The second line allows you to print the value of a specific field 'field' that has been added to the NSURLRequest.

    From Apple docs

    - (NSString *)valueForHTTPHeaderField:(NSString *)field Parameters
    

    field

    The name of the header field whose value is to be returned. In keeping with the HTTP RFC, HTTP header field names are case-insensitive.

    Return Value

    The value associated with the header field field, or nil if there is no corresponding header field.

提交回复
热议问题