POST请求

来源:互联网 发布:ansys15.0软件 编辑:程序博客网 时间:2024/06/05 11:08


@interface ShopController ()<UIWebViewDelegate>


@property (nonatomic,retain)UIView *view;

@property (nonatomic,strong)UIWebView *webView;


@end


@implementation ShopController


//设置下面TabBar的图标和标题以及tag

-(id)init

{

    if (self=[superinit]) {

        self.tabBarItem=[[UITabBarItemalloc]initWithTitle:@"商城"image:[UIImage imageNamed:@"money.png"]tag:2];

    }

    return  self;

}

- (void)viewDidLoad

{

    [superviewDidLoad];

    

    self.view.backgroundColor=[UIColorwhiteColor];

    //设置NavigationItem上面的标题。

    self.navigationItem.title=@"网上商城";

    

    self.webView=[[UIWebViewalloc]initWithFrame:CGRectMake(0,0, self.view.bounds.size.width,self.view.bounds.size.height)];

    //设置设个界面的WebViewdelegate就是这个界面本身。

    self.webView.delegate=self;

    

    NSURL *url = [NSURLURLWithString: @"http://192.168.1.171/opencart/index.php?route=account/login"];

    NSString *body = [NSStringstringWithFormat:@"email=%@&password=%@",@"13715202924",@"Abcd1234"];

    NSMutableURLRequest *request = [[NSMutableURLRequestalloc]initWithURL: url];

    [request setHTTPMethod: @"POST"];

    [request setHTTPBody: [bodydataUsingEncoding: NSUTF8StringEncoding]];

    [self.webView loadRequest: request];

    

    [self.view addSubview:self.webView];

    

}


- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType

{

    return YES;

}

@end

0 0
原创粉丝点击