我正在iPhone上的.aspx
上加载一个UIWebView
网络表单,表单已成功加载。现在表单中有一个选择照片按钮,用户可以从iPhone图库和一个提交按钮中选择照片/图像。选择照片后,当我点击表单上的提交按钮时,它会抛出“request body stream exhausted
”之类的错误。我也在谷歌搜索但没有运气。
这是代码段
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[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"];//image/jpeg
[theRequest setValue:@"image/jpeg" forHTTPHeaderField:@"Content-Type"];// "Content-Type" = "text/html; charset=utf-8";
[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;
/* SET YOUR credentials, i'm just hard coding them in, tweak as necessary */
[[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);
/** THIS IS WHERE YOU SET MAKE THE NEW REQUEST TO UIWebView, which will use the new saved auth info **/
[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;
/* pretty sure i'm leaking here, leave me alone... i just happen to leak sometimes */
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];
}
但我可以上传图片并从设备上的Safari应用程序提交表单。请帮我。提前谢谢。