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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:59:06+00:00 2026-05-15T23:59:06+00:00

This is my code: NSError *error; NSURLResponse *response; NSData *dataReply; NSString *stringReply; NSMutableURLRequest *request

  • 0

This is my code:

    NSError *error;
NSURLResponse *response;
NSData *dataReply;
NSString *stringReply;

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: URLGOESHERE]];
[request setHTTPMethod: @"GET"];
dataReply = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
stringReply = [[NSString alloc] initWithData:dataReply encoding:NSUTF8StringEncoding];

I want to put that in a function soo that i can call it from all my other buttons but i can set the

URLWithString: URLGOESHERE]];

how would i do this and how would i call it ?

Thanks

Mason

  • 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-15T23:59:06+00:00Added an answer on May 15, 2026 at 11:59 pm

    See the explanation below for why this is a bad idea.

    - (NSString *)sendRequestWithURLString:(NSString *)urlString {
        NSError *error;
        NSURLResponse *response;
        NSData *dataReply;
        NSString *stringReply;
    
        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: [NSURL URLWithString:urlString]];
        [request setHTTPMethod: @"GET"];
        dataReply = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
        stringReply = [[NSString alloc] initWithData:dataReply encoding:NSUTF8StringEncoding];
        return [stringReply autorelease];
    }
    

    Then

    NSString *response = [self sendRequestWithURLString:@"....."];
    

    So, take note, if you call this from a button, it will block the main thread until it finishes, which is bad. You need to look into asynchronous requests, or at the very least use dispatch_async.

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

Sidebar

Related Questions

This code: NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@http://www.cnn.com]]; [req setHTTPMethod:@GET]; NSURLResponse *res; NSError *err;
Please consider this code: NSString *jsonreturn = [[NSString alloc] initWithContentsOfURL:[ NSURL URLWithString:url ]]; //
I have this piece of code : - (void)connection:(NSURLConnection*)connection didReceiveResponse:(NSURLResponse*)response { if ([response respondsToSelector:@selector(statusCode)])
I have this code: NSError *error; // NSMigrationManager hates it if you don't provide
Have a look to this code snippet:- -(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { [webData setLength:
My iPhone app is crashing and getting EXC_BAD_ACCESS error when using this code: NSError
This code below allows me to find the word error in all my files
This code gives me this error:Cannot implicitly convert type ArrayList[] to ArrayList[][] at this
This code fails on some machines: // Parse error: syntax error, unexpected '[' ...
Ever since I added this async request, I'm getting an xcode error of Sending

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.