我有一个电子商务应用,并为addCart添加产品ID和数量。在这里,我检查静态样本值并将此值传递给url以进行检查。如果此值匹配,我需要重定向添加到购物车网址页面。在浏览器中它正在工作。但在移动应用程序中,当我单击按钮时,我需要检查值是否相同,我需要重定向。但它没有重定向。
int i=2;
NSString *post =[[NSString alloc] initWithFormat:@"password=%d",i];
NSLog(@"PostData: %@",post);
NSURL *url=[NSURL URLWithString:[NSString stringWithFormat:@"http://serverurl.net/projects/AR/create_cart.php?id=%d",i]];
NSLog(@"url is %@",url);
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
// [NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];
NSError *error = [[NSError alloc] init];
NSHTTPURLResponse *response = nil;
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *responseData = [[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
NSLog(@"Response code: %d", [response statusCode]);
if ([responseData length]){
NSLog(@"Response ==> %@", responseData);
NSMutableDictionary *dict=[responseData JSONValue];
NSLog(@"dict is %@",dict);
NSInteger success = [(NSNumber *) [dict objectForKey:@"success"] integerValue];
NSLog(@"%d",success);
if(success == 1){
}
答案 0 :(得分:0)
目前尚不清楚您使用的是哪个电子商务平台。万一它恰好是Magento,以下是如何重定向用户在iOS应用中登录:https://github.com/mobstac/JustPaws/blob/master/MobstacShop/AuthViewController.m。
我们遇到了同样的问题,并通过捕获WebView的响应来解决它。