Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7989111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:39:17+00:00 2026-06-04T12:39:17+00:00

My app pulls data from a website which uses Form based authentication. It needs

  • 0

My app pulls data from a website which uses Form based authentication. It needs to transparently react to a redirection to the login page & provide the requested credentials via a POST request.

I’ve previously used ASIHTTPREQUEST & then gone through a process of checking the url to see if I’ve been redirected to the authentication page & if so sending the POST request with the login form variables & then making the original request again. It works but is a bit of a hack.

I’m presently moving my code over to AFNetworking & wondering if there is a more elegant way of achieving this, perhaps injecting an auth header? to get AFHTTPClient to trigger the authentication delegate methods when a redirect to the auth page occurs & then posting the form. Here’s a bit of pseudo code:

- (void)requestFinished:(ASIHTTPRequest *)request {
if ([Connection isAuthURL:[request url]])
{
    // If so have we just tried to login ?
    if ( requestState == requestStateSendingLoginCredentials )
    {
        // Login Failed - tried to login & been redirected back to login page
        [self requestFailed:request];
    }
    else
    {
        // We have been directed to login page after a page request
        requestState = requestStateSendingLoginCredentials
        [self postLoginForm:request];
    }
}
else 
{ // Not the authentication page
    if ( requestState == requestStateSendingLoginCredentials )
    {   // We must have successfully logged in
        requestState = requestStateSuccessful;
        // If it was a form we need to post again now were logged in.
        if ([lastRequest isAForm])
        {
            // If original request that triggered the login was a POST request
            // we have to re-send it.
            [self requestURL:nil]; // This will send the last request again
            return;
        }
    }
    if (requestState == requestStateSuccessful)
    {
        [self processResponse:request];
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T12:39:19+00:00Added an answer on June 4, 2026 at 12:39 pm

    Make things easy on yourself and use what HTTP gives you.

    HTTP defines status codes that tell you whether a request was successful (200) or if they require authorization (401).

    Store your credentials in an Authorized HTTP header for your shared AFHTTPClient instance, and you’ll be authenticated for all subsequent calls.

    Or, if those aren’t doing it, you can use AFURLConnection -setAuthenticationChallengeBlock: to respond to authentication challenges.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a personal app that scrapes data from a website. It currently pulls
I'm currently designing an app that pulls map data from a service and renders
I have a Silverlight 4 app which pulls entities down from a database using
I'm refactoring some code so that my app will pull data from a website
Currently my app pulls data from an Microsoft SQL 2005 database via ASP.NET XML
I have a Silverlight Windows Phone 7 app that pulls data from a public
My app needs to pull data from MULTIPLE sources. The following needs to be
I am developing an iPhone app in Xcode which brings data from the SQL
I'm building an app that pulls data in from an excel .csv file and
I'm creating an app that pulls data from a web server (MySQL), parses it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.