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

  • Home
  • SEARCH
  • 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 625777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:20:47+00:00 2026-05-13T19:20:47+00:00

This code snippet isn’t working, I’m getting an Authentication Failed. response from the server.

  • 0

This code snippet isn’t working, I’m getting an “Authentication Failed.” response from the server. Any ideas?

    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] 
                                    initWithURL:
                                    [NSURL URLWithString:@"http://www.tumblr.com/api/write"]];
    [request setHTTPMethod:@"POST"];
    [request addValue:_tumblrLogin forHTTPHeaderField:@"email"];
    [request addValue:_tumblrPassword forHTTPHeaderField:@"password"];
    [request addValue:@"regular" forHTTPHeaderField:@"type"];
    [request addValue:@"theTitle" forHTTPHeaderField:@"title"];
    [request addValue:@"theBody" forHTTPHeaderField:@"body"];

    NSLog(@"Tumblr Login:%@\nTumblr Password:%@", _tumblrLogin, _tumblrPassword);

    [NSURLConnection connectionWithRequest:request delegate:self];

    [request release];

Both _tumblrLogin and _tumblrPassword are run through stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding elsewhere in my code. My login email is of the form “address+test@test.com”. It works just fine for logging in directly to tumblr, but I’m wondering if the “+” character is causing problems with the encoding? It’s not being escaped. Should it be?


Thanks to Martin’s suggestion, I’m now using CFURLCreateStringByAddingPercentEscapes to escape my login and password. I’m still having the same issue, though, my Authentication is failing.

  • 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-05-13T19:20:48+00:00Added an answer on May 13, 2026 at 7:20 pm

    The problem is that you are not creating a proper HTTP POST request. A POST request requires a properly formatted multipart MIME-encoded body containing all the parameters you want to send to the server. You are trying to set the parameters as HTTP headers which won’t work at all.

    This code will do what you want, note especially the NSString categories that create a valid Multipart MIME string:

    @interface NSString (MIMEAdditions)
    + (NSString*)MIMEBoundary;
    + (NSString*)multipartMIMEStringWithDictionary:(NSDictionary*)dict;
    @end
    
    @implementation NSString (MIMEAdditions)
    //this returns a unique boundary which is used in constructing the multipart MIME body of the POST request
    + (NSString*)MIMEBoundary
    {
        static NSString* MIMEBoundary = nil;
        if(!MIMEBoundary)
            MIMEBoundary = [[NSString alloc] initWithFormat:@"----_=_YourAppNameNoSpaces_%@_=_----",[[NSProcessInfo processInfo] globallyUniqueString]];
        return MIMEBoundary;
    }
    //this create a correctly structured multipart MIME body for the POST request from a dictionary
    + (NSString*)multipartMIMEStringWithDictionary:(NSDictionary*)dict 
    {
        NSMutableString* result = [NSMutableString string];
        for (NSString* key in dict)
        {
            [result appendFormat:@"--%@\r\nContent-Disposition: form-data; name=\"%@\"\r\n\r\n%@\r\n",[NSString MIMEBoundary],key,[dict objectForKey:key]];
        }
        [result appendFormat:@"\r\n--%@--\r\n",[NSString MIMEBoundary]];
        return result;
    }
    @end
    
    
    @implementation YourObject
    - (void)postToTumblr
    {
        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] 
                                        initWithURL:
                                        [NSURL URLWithString:@"http://www.tumblr.com/api/write"]];
        [request setHTTPMethod:@"POST"];
        //tell the server to expect 8-bit encoded content as we're sending UTF-8 data, 
        //and UTF-8 is an 8-bit encoding
        [request addValue:@"8bit" forHTTPHeaderField:@"Content-Transfer-Encoding"];
        //set the content-type header to multipart MIME
        [request addValue: [NSString stringWithFormat:@"multipart/form-data; boundary=%@",[NSString MIMEBoundary]] forHTTPHeaderField: @"Content-Type"];
    
        //create a dictionary for all the fields you want to send in the POST request
        NSDictionary* postData = [NSDictionary dictionaryWithObjectsAndKeys:
                                     _tumblrLogin, @"email",
                                     _tumblrPassword, @"password",
                                     @"regular", @"type",
                                     @"theTitle", @"title",
                                     @"theBody", @"body",
                                     nil];
        //set the body of the POST request to the multipart MIME encoded dictionary
        [request setHTTPBody: [[NSString multipartMIMEStringWithDictionary: postData] dataUsingEncoding: NSUTF8StringEncoding]];
        NSLog(@"Tumblr Login:%@\nTumblr Password:%@", _tumblrLogin, _tumblrPassword);
        [NSURLConnection connectionWithRequest:request delegate:self];
        [request release];
    }
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 376k
  • Answers 376k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If the methods have the same values as the file… May 14, 2026 at 8:28 pm
  • Editorial Team
    Editorial Team added an answer You a file with the filename 'export.csv' twice, once when… May 14, 2026 at 8:28 pm
  • Editorial Team
    Editorial Team added an answer You should run the sync process on a separate thread… May 14, 2026 at 8:28 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.