I upload one web form .aspxto UIWebViewan iPhone and the form loads successfully. Now the form has one photo selection button, where users can select a photo / image from the iPhone gallery and one submit button. Having selected the photo, and when I click the submit button on the form, it gives an error, for example, " request body stream exhausted". I also searched on google but no luck. Here is a snippet of code
- (void)viewDidLoad
{
[super viewDidLoad];
[activity startAnimating];
activity.hidden = NO;
NSURL *url = [NSURL URLWithString:@"http://rest..com:95134/MobileForm.aspx?processName=NewForm"];
theRequest = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60];
[theRequest setHTTPMethod:@"POST"];
[theRequest setValue:@"application/x-www-form-urlencoded charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest setValue:@"image/jpeg" forHTTPHeaderField:@"Content-Type"];
[webView loadRequest:theRequest];
}
#pragma mark
#pragma mark connection Methods
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge;
{
NSLog(@"got auth challange");
if ([challenge previousFailureCount] == 0) {
_authed = YES;
[[challenge sender] useCredential:[NSURLCredential credentialWithUser:@"user" password:@"pass" persistence:NSURLCredentialPersistenceForSession] forAuthenticationChallenge:challenge];
} else {
[[challenge sender] cancelAuthenticationChallenge:challenge];
}
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response;
{
NSLog(@"received response via nsurlconnection %@",response);
[connection cancel];
[webView loadRequest:theRequest];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
activity.hidden =YES;
NSLog(@"err %@", [error localizedDescription]);
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Message" message:[error localizedDescription] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
- (BOOL)connectionShouldUseCredentialStorage:(NSURLConnection *)connection;
{
return YES;
}
#pragma mark
#pragma mark webView Methods
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;
{
NSLog(@"Did start loading: %@ auth:%d", [[request URL] absoluteString], _authed);
if (!_authed) {
_authed = NO;
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[connection start];
return NO;
}
return YES;
}
- (void)webViewDidStartLoad:(UIWebView *)webView{
activity.hidden = NO;
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{
activity.hidden = YES;
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
activity.hidden = YES;
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Message" message:[error localizedDescription] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
But I was able to upload the image and submit the form from the Safari application on the device. Please help me. Thanks in advance.
source
share