NSURLRequest setHTTPBody 只读

NSURLRequest setHTTPBody readonly

NSURLRequest *r = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:path]];
[r setHTTPBody:imageData];
r.HTTPBody = imageData;

Xcode 在第二行给出错误:"No visible interface for 'NSURLRequest declares the selector 'setHTTPBody'"

和第三行"Assignment to readonly property"

但 class 定义显示

/*! 
    @method HTTPBody:
    @abstract Sets the request body data of the receiver.
    @discussion This data is sent as the message body of the request, as
    in done in an HTTP POST request.
    @param data the new request body data for the receiver.
*/
@property (copy) NSData *HTTPBody;

常规 NSURLRequest 是不可变的。使用 NSMutableURLRequest

您提供了来自 NSMutableURLRequest 的定义,但使用 NSURLRequest,其中此 属性 是只读的。