Я пытаюсь получить данные с сервера. Я использую NSURLConnectionDelegate, NSURLConnectionDataDelegate. Существует код (Objective-C).
-(void)sendRequest
{
NSURL* url = [[NSURL alloc] initWithString:@"http://SomeServer"];
NSMutableURLRequest* request = [[NSMutableURLRequest alloc] init];
NSString* reqBody = [NSString stringWithFormat:@"<tag>Content</tag>"];
NSData* reqData = [reqBody dataUsingEncoding:NSUTF8StringEncoding];
NSInputStream* stream = [NSInputStream inputStreamWithData:reqData];
[request setURL:url];
[request setHTTPBodyStream:stream];
[request setHTTPMethod:@"POST"];
self.wpData = [[NSMutableData alloc] init];
NSURLConnection* conection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[conection start];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[self.wpData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)d {
NSString* str = [[NSString alloc] initWithData:d encoding:NSUTF8StringEncoding];
NSLog(@"RESPONSE DATA: %@",str);
[self.wpData appendData:d];
}
Но я получаю "411 - Length Required", когда я использую
[request setHTTPBodyStream:stream];
и "HASH (someAddress)", когда я использую
[request setHTTPBody:reqData];
Я пробовал
[request setHTTPBodyStream:stream];
NSString *postLength = [NSString stringWithFormat:@"%d", [reqData length]];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
но снова "HASH (someAdddress)"
Чем я ошибся? Извините за мой английский. Спасибо:)