开发者

Uploading video file to the URL

开发者 https://www.devze.com 2023-01-25 18:29 出处:网络
I am trying to upload video file to the specified URL. When I press button video file should upload into the URL which I used. But no response is coming.

I am trying to upload video file to the specified URL. When I press button video file should upload into the URL which I used. But no response is coming.

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];
    
}
else
{
    
}

}

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    
    [webData12 setLength:0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{   
    
    [webData12 appendData:data];
开发者_Python百科}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    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];
    }
}


you need to send the request, add this line after you set the HTTPBody

NSData *serverReply = [NSURLConnection sendSynchronousRequest: request12 returningResponse:&response error:&error];
0

精彩评论

暂无评论...
验证码 换一张
取 消