Iphone CSRF验证失败。iOS中的Pinterest请求中止错误
我正在尝试在iOS应用程序中集成Iphone CSRF验证失败。iOS中的Pinterest请求中止错误,iphone,ios,uiwebview,csrf,pinterest,Iphone,Ios,Uiwebview,Csrf,Pinterest,我正在尝试在iOS应用程序中集成Pinterest 这是我试过的 - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. } - (void)viewWillAppear:(BOOL)animated { [_pinterestWebView.scrollView setShowsHorizontalScroll
Pinterest
这是我试过的
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)viewWillAppear:(BOOL)animated
{
[_pinterestWebView.scrollView setShowsHorizontalScrollIndicator:NO];
[_pinterestWebView.scrollView setShowsVerticalScrollIndicator:NO];
[super viewWillAppear:animated];
[self postToPinterestWithImageUrl:_url andDescription:_description];
}
-(void)postToPinterestWithImageUrl:(NSString *)url andDescription:(NSString *)description
{
NSString *buttonUrl = [NSString stringWithFormat:@"http://pinterest.com/pin/create/button/?url=http://www.flor.com&media=%@&description=%@", url, @"hello"];
[_pinterestWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:buttonUrl] cachePolicy:NSURLCacheStorageNotAllowed timeoutInterval:40]];
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSLog(@"WebView URL = %@",[request.URL absoluteString]);
return YES;
}
- (void)webViewDidStartLoad:(UIWebView *)webView {
[_activityIndicator startAnimating];
[_activityIndicator setHidden:NO];
}
-(void)webViewDidFinishLoad:(UIWebView *)webView {
NSRange range = [[webView.request.URL absoluteString] rangeOfString:@"login"];
if (range.location==NSNotFound) {
CGRect modifiedFrame = self.view.superview.frame;
CGPoint center = self.view.superview.center;
UIInterfaceOrientation orinetation= [[UIApplication sharedApplication] statusBarOrientation];
if (UIInterfaceOrientationIsLandscape(orinetation)) {
modifiedFrame.size=CGSizeMake(350, 650);
}
else
{
modifiedFrame.size=CGSizeMake(650, 350);
}
[self.view.superview setFrame:modifiedFrame];
[self.view.superview setCenter:center];
NSLog(@"Content Offset = %@",NSStringFromCGPoint(webView.scrollView.contentOffset));
[webView.scrollView setContentOffset:CGPointMake(40, 0)];
}
NSLog(@"Content Size = %@",NSStringFromCGSize([webView.scrollView contentSize]));
[_activityIndicator stopAnimating];
[_activityIndicator setHidden:YES];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
NSLog(@"Error = %@",[error localizedDescription]);
}
- (void)viewDidUnload
{
[self setActivityIndicator:nil];
[self setPinterestWebView:nil];
[super viewDidUnload];
}
- (IBAction)dismissIt:(id)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
}
-(BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return YES;
}
但是,一旦webview加载了pinterest
login页面&如果我改变方向并尝试登录,那么我将在webview上显示以下消息
有什么问题吗?
我在加载Pinterest
url时有没有出错?
此外,它总是提示进行身份验证。如何避免这种情况?发生的情况是,您试图在没有Django CSRF(跨站点请求伪造)令牌的情况下向Pinterest发出请求。您需要获取该CSRF令牌并将其放入在
postToPinterestWithImageUrl
中发出的请求中。此外,在尝试以这种方式与Pinterest交互时,您可能希望使用POST而不是GET请求。此外,您每次都必须登录的原因是,您正在使用nsurlcachestagenotallowed
作为缓存策略,该策略确保HTTP会话的任何内容(包括会话信息)都不会保存到磁盘。尝试将缓存策略更改为NSURLCacheStorageAllowed
@sashimi。。我不明白你的意思。。即使我删除了缓存策略,也会得到同样的错误。还有,如何提出post请求?你能给我举一个Pinterest中POST请求的例子吗?我正在使用来自github的示例代码。他也在使用GET。你应该像他在那个项目中那样将HTML加载到webview中,并包括所有相关的javascript等。现在你只是直接向Pinterest发出GET请求,可能需要Pinterest JS修改。但是,我不想用HTML按钮点击操作来完成。如果要在我单击iOS本机按钮时发布。有没有别的办法寄到品特瑞斯特?pinterest中是否有POST
请求?您最好通过webview进行操作,因为pinterest没有公共API。见编号。。查看此应用程序。他不是在用webview做这件事<代码>itunes.com/apps/mazcontrol