iphone - ASIHttpRequest登录身份验证问题

标签 iphone ios web-services authentication asihttprequest

我正在尝试通过网站验证用户名和密码...

我像这样使用 ASIHttpRequest:

- (IBAction)fetchTopSecretInformation:(id)sender{
  Ustr = User.text;    //Ustr and Pstr are strings 
  Pstr  = Pass.text;

  NSURL *url1 = [NSURL URLWithString:[NSString stringWithFormat:@"https://www.MySite/login/"]];
  ASIFormDataRequest *request1 = [ASIFormDataRequest requestWithURL:url1];
  [request1 setUseKeychainPersistence:YES];
  request1.delegate = self;
  request1.shouldPresentCredentialsBeforeChallenge = YES;

  [request1 setRequestMethod:@"POST"];
  [request1 setPostValue:User.text forKey:@"username"];
  [request1 setPostValue:Pass.text forKey:@"passwd"];
  [request1 setTimeOutSeconds:30];
  NSLog(@"Useer :%@",User.text);

  [request1 setDidFailSelector:@selector(topSecretFetchFailed:)];
  [request1 setDidFinishSelector:@selector(topSecretFetchComplete:)];
  [request1 startAsynchronous];
}

- (IBAction)topSecretFetchFailed:(ASIHTTPRequest *)theRequest{
  UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Error sending request to the server" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
  [alert show];
}

- (IBAction)topSecretFetchComplete:(ASIHTTPRequest *)theRequest{
  int statusCode = [theRequest responseStatusCode];
  NSString *statusMessage = [theRequest responseStatusMessage];

  NSString *strResponse = [[theRequest responseString] stringByTrimmingCharactersInSet:    [NSCharacterSet whitespaceAndNewlineCharacterSet]];
  NSString *strFinal = [self flattenHTML:strResponse];
  NSLog(@"Response :%@",strFinal);
  NSLog(@"StatusCode: %d", statusCode);
  NSLog(@"StatusMessage: %@", statusMessage);
}

我在 NSLog 中得到如下响应:

jQuery(function($) { $(".main").addClass("show-bg"); });

JavaScript seems to be disabled in your browser.
You must have JavaScript enabled in your browser to utilize the functionality of this website.                

This is a demo store. Any orders placed through this store will not be honored or fulfilled.

                        +995 91 190601

            მოგესალმებით ელექტრონული წიგნების მაღაზიაში 

                        READERwill.com

    კალათა



                        კალათა GEL 0,00
                            სავაჭრო კალათა ცარიელია.

ჩემი ბიბლიოთეკა
სურვილები
რეგისტრაცია

.
.
.
.
.

状态代码和状态消息是

StatusCode: 200
StatusMessage: HTTP/1.1 200 OK

这个响应是什么以及如何使用它进行身份验证

在我的网络服务中,如果用户名和密码正确,则会显示“成功”消息,否则会显示失败消息...

最佳答案

如果您正在从事新项目,那么您不应该使用 ASIHTTP 框架。检查此链接 http://allseeing-i.com/ASIHTTPRequest/ 中给出的说明最后一次更新是在 2011 年。

尝试在 NSLog 中仅显示“strResponse”。我认为它应该正确显示响应。

关于iphone - ASIHttpRequest登录身份验证问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18074541/

相关文章:

ios - UITransitionContextFromViewControllerKey 返回错误的 ViewController

java - 如何在 Java Web 服务 SOAP 中注入(inject) EJB

asp.net - Web 服务互操作性 - wsdl 复杂类型扩展

java - Android,使用 Retrofit 填充无尽 ListView 数据的最佳方法?

javascript - jquery的scrolltop和scrollleft工作得很好,但是在iphone上它们都将另一个栏滚动到它的起始位置?

iphone - 具有空部分的 nsfetchedresultscontroller

ios - 一些 UITableView 单元格在向下滚动然后返回后消失

iphone - 使用 Blue Marble Drop 在 Google/Apple map 上显示多个用户的位置

ios - 使用 Alamofire 解析字典中的 json 对象

iPhone 推送通知在 Rails 应用程序中不起作用 - apn_sender