IOS>使用POST在Safari中打开URL [英] IOS > Open URL in Safari with POST

查看:246
本文介绍了IOS>使用POST在Safari中打开URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从UIView发送POST数据在Safari中启动一个URL。这将允许我加载我的Paypal页面。

I'd like to launch a URL in Safari from UIView sending POST datas. This would allow me to load my Paypal page.

通常,在HTML中我们必须这样做:

Normally, in HTML we have to do this :

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" style="text-align:center;" target="_blank">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="XXXXXXXXXXX">
<input type="submit" value="Faire un don" id="donpaypal">
</form>

我知道我可以用这几行打开一个新的URL:

I know that I can open a new URL with this few lines :

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"http:://I.have.a.beautifull.website.com"]];

是否有指定POST数据的意思或者你有意思?

Is there a mean to specify POST datas OR would you have a mean?

推荐答案

我建议您使用UIWebView实现自定义浏览器。
UIWebView可以加载NSURLRequest。
查看以下代码

I suggest you to implement your custom browser using a UIWebView. A UIWebView can load a NSURLRequest. Have a look at the following code

NSString *post = @"yourPostInformation";
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];

[request setURL:[NSURL URLWithString:baseURL]];    
[request setTimeoutInterval:60];

[request setHTTPMethod:@"POST"];
[request setHTTPBody:postData];

[myWebView loadRequest:request];

这篇关于IOS&gt;使用POST在Safari中打开URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆