我正在尝试将视频文件上传到指定的网址。当我按下按钮视频文件应上传到我使用的网址。但没有回复。任何人都可以说明理由。
enter code here
NSString *filePath = [[NSBundle mainBundle]pathForResource:@"3idiots" ofType:@"mov"];
NSURL *uploadurl=[NSURL URLWithString:@"http://115.111.27.206:8081/vblo/upload.jsp"];
//NSData *postVideoData = [NSData dataWithContentsOfFile:filePath];
NSData *postVideoData = [string dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postVideoLength = [NSString stringWithFormat:@"%d", [postVideoData length]];
NSMutableURLRequest *request12 = [[[NSMutableURLRequest alloc] init] autorelease];
[request12 setURL:uploadurl];
[request12 setHTTPMethod:@"POST"];
[request12 setValue:postVideoLength forHTTPHeaderField:@"Content-Length"];
[request12 setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request12 setHTTPBody:postVideoData];
NSURLConnection * theConnection12 = [[NSURLConnection alloc] initWithRequest:request12 delegate:self];
if(theConnection12) { webData12 = [[NSMutableData data] retain];
} 其他 {
}
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[webData12 setLength:0];
} - (void)connection:(NSURLConnection *)连接didReceiveData:(NSData *)数据 {
[webData12 appendData:data];
} - (void)connectionDidFinishLoading:(NSURLConnection *)连接 { NSString * loginStatus12 = [[NSString alloc] initWithBytes:[webData12 mutableBytes] length:[webData12 length] encoding:NSUTF8StringEncoding]; 的NSLog(loginStatus12);
if(loginStatus12)
{
UIAlertView *statusAlert12 = [[UIAlertView alloc]initWithTitle:nil message:(NSString *)loginStatus12 delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:nil];
[statusAlert12 show];
}
}
答案 0 :(得分:0)
您需要发送请求,在设置HTTPBody后添加此行
NSData *serverReply = [NSURLConnection sendSynchronousRequest: request12 returningResponse:&response error:&error];