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 8920521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:17:32+00:00 2026-06-15T06:17:32+00:00

I am using this code to send a JSON to a .NET service to

  • 0

I am using this code to send a JSON to a .NET service to register a user:

NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:
                                deviceID, @"DeviceId",
                                model, @"DeviceModel",
                                user, @"Username",
                                pass, @"Password",
                                email, @"email",
                                nil];

    NSDictionary *consumer = [NSDictionary dictionaryWithObject:dictionary forKey:@"consumer"];
    NSLog(@"%@", consumer);

    NSError *error = nil;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:consumer
                                                       options:kNilOptions
                                                         error:&error];
    NSLog(@"%@", error);

    NSString *urlString = @"http://aservice.co.uk/services/service.svc/RegisterConsumer";

    NSURL *url = [NSURL URLWithString:urlString];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    [request setHTTPMethod:@"POST"];
    [request setValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"];

    [request setHTTPBody:jsonData];
    NSURLResponse *response = NULL;
    NSError *requestError = NULL;
    NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&requestError];
    NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding] ;
    NSLog(@"%@", responseString);
    NSLog(@"%@", requestError);

This works fine as I receive back a JSON result of {"RegisterConsumerResult":"True"}

Now when I try to register a username that I know already exists, I get back the following HTML as the responseString:

<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">   <head>
    <title>Request Error</title>
    <style>BODY { color: #000000; background-color: white; font-family: Verdana; margin-left: 0px; margin-top: 0px; } #content { margin-left: 30px; font-size: .70em; padding-bottom: 2em; } A:link { color: #336699; font-weight: bold; text-decoration: underline; } A:visited { color: #6699cc; font-weight: bold; text-decoration: underline; } A:active { color: #336699; font-weight: bold; text-decoration: underline; } .heading1 { background-color: #003366; border-bottom: #336699 6px solid; color: #ffffff; font-family: Tahoma; font-size: 26px; font-weight: normal;margin: 0em 0em 10px -20px; padding-bottom: 8px; padding-left: 30px;padding-top: 16px;} pre { font-size:small; background-color: #e5e5cc; padding: 5px; font-family: Courier New; margin-top: 0px; border: 1px #f0f0e0 solid; white-space: pre-wrap; white-space: -pre-wrap; word-wrap: break-word; } table { border-collapse: collapse; border-spacing: 0px; font-family: Verdana;} table th { border-right: 2px white solid; border-bottom: 2px white solid; font-weight: bold; background-color: #cecf9c;} table td { border-right: 2px white solid; border-bottom: 2px white solid; background-color: #e5e5cc;}</style>   </head>   <body>
    <div id="content">
      <p class="heading1">Request Error</p>
      <p>The server encountered an error processing the request. See server logs for more details.</p>
    </div>   </body> </html>

Obviously this isn’t returning an actual error, just a web page telling me there was an error.
Have a missed a way to retrieve the actual error code from the service?
Is it possible that the service could be sending the error as a response somehow?

EDIT–
I forgot to mention, the actual errorResponse is nil, I’m assuming because HTML was returned that the actual request is classed as successful.

  • 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-15T06:17:35+00:00Added an answer on June 15, 2026 at 6:17 am

    First off, to check what the status code is so you can handle the >400 errors like so:

    NSURLResponse *response = NULL;
    NSError *requestError = NULL;
    NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&requestError];
    NSUInteger statusCode = [(NSHTTPURLResponse*)response statusCode];
    //Then do your error checking. 
    

    If you want to use AFNetworking it can be pretty simple to do this, just add the library (find it here: http://afnetworking.com) then do it like this:

    //NOTHING CHANGED TIL NEXT COMMENT
    NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:
                                deviceID, @"DeviceId",
                                model, @"DeviceModel",
                                user, @"Username",
                                pass, @"Password",
                                email, @"email",
                                nil];
    
    NSDictionary *consumer = [NSDictionary dictionaryWithObject:dictionary forKey:@"consumer"];
    NSLog(@"%@", consumer);
    
    NSError *error = nil;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:consumer
                                                       options:kNilOptions
                                                         error:&error];
    NSLog(@"%@", error);
    //Start to use AFNetworking
    
        NSURL *baseUrl = [NSURL URLWithString:@"http://aservice.co.uk/services/service.svc/"];
    AFHTTPClient *client = [AFHTTPClient clientWithBaseURL:baseUrl];
    
    NSMutableURLRequest *request = [client requestWithMethod:@"POST" path:@"RegisterConsumer" parameters:dictionary];
    [request setHTTPBody:jsonData];
    
    AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
        NSLog(@"SUCESS");
    } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
        NSLog(@"FAILED WITH STATUS CODE %d - error description: %@", response.statusCode, error);
    }];
    
    [operation start];
    

    This is using an asynchronous connection (you should!) then you can call your next step in the success block.

    I didn’t test this but it should work (or very close ) for what you need to do.

    Update
    Maybe you can use this code (I grabbed from HERE ) to see what kind of data — if any — they are providing in the header and see if it’s useful.

    if ([response respondsToSelector:@selector(allHeaderFields)]) {
        NSDictionary *dictionary = [response allHeaderFields];
        NSLog([dictionary description]);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code written in .NET 4.0 using VS2010 Ultimate Beta 2: smtpClient.Send(mailMsg);
I am using this code to send mail with php http://www.siteduzero.com/tutoriel-3-35146-e-mail-envoyer-un-e-mail-en-php.html#ss_part_4 . This code
Using this code, i am able to send a notification to my own device.
i'm using MFMailComposer to send an image.m using this code MFMailComposeViewController *picker = [[MFMailComposeViewController
When using this code: <script> $(document).ready(function () { $.getJSON(http://twitter.com/statuses/user_timeline/USERNAME.json?callback=?, function(data) { if(data[0].text.length > 107)
Using this code to zip a folder and it works perfect on small files
Using this code var html='<div class=somediv></div>'; var target=document.getElementById('contentArea'); target.appendChild(html); I'm getting Uncaught Error: NOT_FOUND_ERR:
Using This code: I am tring to fill the page with the data and
Im using this code: protected String getContactInfo() { Cursor cursor = getContentResolver().query(ContactsContract.Data.CONTENT_URI, null, null,
Im using this code for mysql connection $con = mysql_connect(localhost:/var/lib/mysql/mysql.sock, abc , xyz); if

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.