Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php AFIT html表单_Php_Iphone_Ios_Magento - Fatal编程技术网

Php AFIT html表单

Php AFIT html表单,php,iphone,ios,magento,Php,Iphone,Ios,Magento,我正在学习使用AFNetworking,希望提交登录表单 我的代码: NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys: @"mymail@yahoo.com",@"login[username]", @"123456", @"login[password]", nil]; NSMutableURLRequest *request = [self requestWithMethod:@"POST" p

我正在学习使用AFNetworking,希望提交登录表单

我的代码:

NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:    @"mymail@yahoo.com",@"login[username]", @"123456", @"login[password]", nil];    
NSMutableURLRequest *request = [self requestWithMethod:@"POST" path:@"index.php/customer/account/loginPost/" parameters:params];
[request setValue:@"foo=bar" forHTTPHeaderField:@"Cookie"];
AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject)
                                     {
                                         NSLog(@"oauthAuthorize Success: %@",    [operation.response allHeaderFields]);

                                     }
                                                                  failure:^(AFHTTPRequestOperation *operation, NSError *error)
                                     {
                                         NSLog(@"oauthAuthorize Fail: %@",operation.responseString); 
                                     }];
[self enqueueHTTPRequestOperation:operation];
我收到的标题是:

    "Cache-Control" = "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
    Connection = "Keep-Alive";
    "Content-Type" = "text/html; charset=UTF-8";
    Date = "Wed, 28 Nov 2012 09:57:03 GMT";
    Expires = "Thu, 19 Nov 1981 08:52:00 GMT";
    "Keep-Alive" = "timeout=5, max=98";
    "Login-Required" = true;
    Pragma = "no-cache";
    Server = "Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7";
    "Set-Cookie" = "frontend=sq26g7l2j45itg9sk6etf249r7; expires=Wed, 28-Nov-2012 10:57:04 GMT; path=/magento_1702; domain=myhost; HttpOnly";
    "Transfer-Encoding" = Identity;
    "X-Powered-By" = "PHP/5.4.7";
我知道我登录失败了,因为当我在浏览器上登录时,如果成功,它将重定向到帐户页面

我在MAC上使用bash进行了此表单的测试操作,结果如下:

Comand:

 curl -v  -F login[username]=mymai@yahoo.com -F login[password]=123456 --header "Cookie:foo=bar" myhost/mypage/index.php/customer/account/loginPost/
结果:

    < Server: Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7
    < X-Powered-By: PHP/5.4.7
    < Set-Cookie: frontend=ui19hig1g1pu43kdsam43naqr6; expires=Wed, 28-Nov-2012 10:46:21 GMT; path=/magento_1702; domain=myhost; HttpOnly
    < Expires: Thu, 19 Nov 1981 08:52:00 GMT
    < Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
    < Pragma: no-cache
    < Set-Cookie: persistent_shopping_cart=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/magento_1702; domain=192.168.1.254; httponly
    < Set-Cookie: frontend=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/magento_1702; domain=192.168.1.254; httponly
    < Set-Cookie: frontend=aaqja98lg13v6pc1qgema98i40; expires=Wed, 28-Nov-2012 10:46:22 GMT; path=/magento_1702; domain=192.168.1.254; HttpOnly
    < Location: http://myhost/magento_1702/index.php/customer/account/
    < Content-Length: 0
    < Content-Type: text/html; charset=UTF-8
标题有位置字段是帐户页的url,没有登录必填字段。我认为这是成功的


请告诉我如何使用AFNetwoking来成功登录,就像使用Bash命令一样

我解决了我的问题。当使用AFNetworking时,完成的块将在所有服务器重定向后被调用。所以,您应该捕获重定向块以获得类似curl命令的响应:

// AFHTTPRequestOperation *operation = ...;
[operation setRedirectResponseBlock:^NSURLRequest *(NSURLConnection *connection, NSURLRequest *request, NSURLResponse *redirectResponse) {
        // first response will come here
    }];
// ...