objective-c – 将AFHTTPRequestOperation的响应传递给UIWebview

objective-c – 将AFHTTPRequestOperation的响应传递给UIWebview,第1张

概述我的代码向服务器发出两个请求.一个进入uiwebview,一个进入AFHTTPRequestOperation.我想使用AFHTTPRequestOperation并将响应传递给我的uiwebview.将响应传递到uiwebview而不是再次加载它的正确语法是什么?如果不从服务器调用两次,我该怎么做?我仍然希望能够测试加载请求的成功或失败,并发送用户名和密码以连接到URL. - (BOOL)tex 我的代码向服务器发出两个请求.一个进入uiwebvIEw,一个进入AFhttpRequestoperation.我想使用AFhttpRequestoperation并将响应传递给我的uiwebvIEw.将响应传递到uiwebvIEw而不是再次加载它的正确语法是什么?如果不从服务器调用两次,我该怎么做?我仍然希望能够测试加载请求的成功或失败,并发送用户名和密码以连接到URL.

- (BOol)textFIEldShouldReturn:(UITextFIEld *)textFIEld {[itemFIEld resignFirstResponder];NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];Nsstring *username = [defaults objectForKey:@"storedUsername"];Nsstring *passWord = [defaults objectForKey:@"storedPassWord"];NSURL *url = [NSURL URLWithString:@"http://www.example.net/"];AFhttpClIEnt *clIEnt = [[AFhttpClIEnt alloc] initWithBaseURL: url];[clIEnt setAuthorizationheaderWithUsername:username password:passWord];NSMutableURLRequest *request = [clIEnt requestWithMethod:@"GET" path:[@"/example/itemlookup.PHP?item=" stringByAppendingString:itemFIEld.text] parameters:nil];AFhttpRequestoperation *operation = [[AFhttpRequestoperation alloc] initWithRequest:request];[operation setCompletionBlockWithSuccess:^(AFhttpRequestoperation *operation,ID responSEObject) {    //calling again here was the only way I Could figure out to get this into my webvIEw    //need to get response from above and put into the uiwebvIEw    [webVIEw loadRequest:request];    NSLog(@"Success");} failure: ^(AFhttpRequestoperation *operation,NSError *error) {    NSLog(@"Failure"); }];NSOperationQueue *queue = [[NSOperationQueue alloc] init];[queue addOperation:operation];return YES; }
解决方法 我建议使用AFNetworking的UIWebVIEw类别,它正是这样做的;使用AFhttpRequestoperation加载网页内容,然后将其作为HTML字符串加载到Web视图中.

否则,我建议您查看该类别,看看您是否可以调整其代码供您使用. https://github.com/AFNetworking/AFNetworking/blob/master/UIKit%2BAFNetworking/UIWebView%2BAFNetworking.m

总结

以上是内存溢出为你收集整理的objective-c – 将AFHTTPRequestOperation的响应传递给UIWebview全部内容,希望文章能够帮你解决objective-c – 将AFHTTPRequestOperation的响应传递给UIWebview所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1004695.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存