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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:48:36+00:00 2026-05-29T04:48:36+00:00

Java Code need to write an equivalent in objectiveC. CAn you please help me

  • 0

Java Code need to write an equivalent in objectiveC.

CAn you please help me out:

JavaCode
URL url;

HttpURLConnection urlConn;
            DataOutputStream printout;
            BufferedReader input;
            url = new URL(IDP_URL);
            urlConn = (HttpURLConnection) url.openConnection();
            urlConn.setDoOutput(true);
            urlConn.setDoInput(true);
            urlConn.setRequestProperty("accept", "application/json");
            urlConn.setRequestMethod("POST");
            // Specify the content type.
            urlConn.setRequestProperty("Content-Type", "text/plain");
            // Send POST output.
            printout = new DataOutputStream(urlConn.getOutputStream());
            String content = "username="
                    + URLEncoder.encode(username, UTF_8_TYPE)
                    + "&password="
                    + URLEncoder.encode(password, UTF_8_TYPE)
                    + "&client_assertion_type="
                    + URLEncoder.encode(tokenType, UTF_8_TYPE)
                    + "&client_assertion="
                    + URLEncoder.encode(appToken, UTF_8_TYPE)
                    + "&spEntityID="
                    + URLEncoder.encode("http://localhost:8080/opensso",
                            UTF_8_TYPE);
            printout.writeBytes(content);
            printout.flush();
            printout.close();
            // Get response data.
            input = new BufferedReader(new InputStreamReader(urlConn
                    .getInputStream()));
            do {
                str = input.readLine();
            } while (str == null);
            input.close();
        } catch (IOException e) {
            LOGGER.error("Exception: ", e);
        }

Equivalent ios code:

- (NSString *)urlEncodeValue:(NSString *)str
{

    //            NSString *result = (NSString *) CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)str, NULL, CFSTR(":/?#[]@!$&()*+,;="), kCFStringEncodingUTF8);
    //            return [result autorelease];
    return [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
}

-(void) IdpServiceCall {


    NSString* strRequest = [NSString stringWithFormat:@"username=%@&password=%@&client_assertion_type=%@&client_assertion=%@&spEntityID=%@",
     [self urlEncodeValue:strUsrName],[self urlEncodeValue:strPasswrd],[self urlEncodeValue:@"JWT"],[self urlEncodeValue:strAppTknContent],[self urlEncodeValue:@"http://localhost:8080/opensso"]];
    NSHTTPURLResponse  *response = nil;
    NSError *error = nil;       
    NSURL *nsurl = [[NSURL alloc] initWithString:@"http://10.230.148.253:8080/IDP/services/login/authuser"];  
    NSMutableURLRequest*   urlRequest = [[NSMutableURLRequest alloc] initWithURL:nsurl]; 
        NSData* dataRequest = [NSData dataWithBytes:[strRequest UTF8String] length:[strRequest length]];//this line is for making the nsstring to utf8string and not encoding
        [urlRequest setHTTPMethod: @"POST"];
        [urlRequest setHTTPBody: dataRequest];
    NSString *contentType = [NSString stringWithFormat:@"text/plain"];
    [urlRequest setValue:contentType forHTTPHeaderField:@"Content-Type"];
    [urlRequest setTimeoutInterval:3.0];
    [urlRequest setCachePolicy:NSUrl];    

    NSData *responseData =[NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error];

NSString *result =[[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding];   
        NSLog(@"downloaded idp output  %@",result);     
}

im not getting the desired output it 0 bytes.

Please spot me the issue.Would be greatful.

  • 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-29T04:48:37+00:00Added an answer on May 29, 2026 at 4:48 am

    Your code looks fine, only the NSData for the HTTP Body looks odd.
    Try to build your data more like this:

        appToken = [prefs objectForKey:@"Applicasa appToken"];
        [data appendData:[[NSString stringWithFormat:@"%@=%@",@"Key",@"Value"] dataUsingEncoding:NSUTF8StringEncoding]];
        [_request setHTTPBody:data];
    

    Let me know if you it worked for you

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

Sidebar

Related Questions

I need to convert a python code into an equivalent java code. Python makes
I need to run an external application from within my Java code. I can
I need to write some junit tests on Java code that calls Math.random() .
I need to write a java code that watches the applications. Whenever the user
I need to write a code that compares performance of Java's ArrayList with Scala's
I need to write some Java code to connect to an LDAP server to
I need some points on: How can one read/recover deleted files, in Java code.
I have existing java code and need to create Design Document based on that.
I need the java code snippet for the below logic: Following is a string
I need to ship some Java code that has an associated set of data.

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.