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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:25:36+00:00 2026-05-26T17:25:36+00:00

I know how to send post/get request using any HTTPClient which are explained here

  • 0

I know how to send post/get request using any HTTPClient which are explained here and here. But now I have a stream socket connected to a remote server and I want to send a post request using this socket.

I never done that before and frankly never considered a concept of POST/GET via socket. But my googling led me to this, where post is done via a java socket..

I am using CFSocket libraries provided by Apple..Is there anyway to do POST/GET using socket in Objective-C?

  • 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-26T17:25:36+00:00Added an answer on May 26, 2026 at 5:25 pm

    Well I have been able to do GET/POST using plain CFSocket.

    -(bool) sendHTTPHeader{
        NSMutableString* requestString  =   [[NSMutableString alloc] init];
        NSString *pathString            =   [NSString stringWithFormat:@"/remote_function.jsp?argument1=%@&argument2=%@",arg1,arg2 ];
        [requestString appendFormat:@"GET %@ HTTP/1.x\r\n",pathString];
        [requestString appendFormat:@"HOST:%@",your_host_here];
        [requestString appendFormat:@"User-Agent:any\r\n"];
        [requestString appendFormat:@"Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n\r\n"];
        /*If there are more parameters requested by server, put them here..*/
    
        const char* sendString          =   [requestString UTF8String];
    
        CFDataRef  data                 =   CFDataCreate(NULL, (const UInt8*)sendString, strlen(sendString));
        CFSocketError err               =   CFSocketSendData(clientSocket, NULL, data, 0);
        if (err != kCFSocketSuccess) {
            NSLog(@"Error in sending data to the server");
            CFRelease(data);
            return FALSE;
        }
        [requestString release];
        CFRelease(data);
        return TRUE;
    }
    

    Now in your socket callback function you can read the http response..Hope this will help someone..

    void socketCallback(CFSocketRef socket,CFSocketCallBackType type,CFDataRef address,const void *data,void *info){
        if (type == kCFSocketDataCallBack) {
            NSData *nsData              =   (NSData *)data;
            if ([nsData length] == 0) {
                NSLog(@"Connection dropped by remote socket");
                return;
            }
            //Control reaches here when there is a chunk of data to read
            CFDataRef df                =   (CFDataRef) data;
            int len                     =   CFDataGetLength(df);
            CFRange range               =   CFRangeMake(0,len);
            UInt8 buffer[len+1];
    
            if(len <= 0) {
                NSLog(@"No data read");
                return;        
            }
            memset((void*)buffer,0,sizeof(buffer));
            CFDataGetBytes(df, range, buffer);
            NSString *byteString            =   [[NSString alloc] initWithBytes:buffer length:len encoding:NSUTF8StringEncoding];
            NSLog(@"byte string is : %@",byteString);
            [byteString release];
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know how to send a post request in curl and
I have a custom Http Handler which manipulates HTTP POST and GET. I got
I need to encode the body of my POST request but I don´t know
I know how to send mails using the Microsoft Enterprise Library 2.0 using a
I know that it's possible to get SVN to send emails after a commit
I know how to write the basic c# code to send emails, but I'm
I am in my Terminal and I want to send a POST request to
I would like to send a POST request to a server, I don't want
I'm trying to send a simple POST request to a REST web service and
I have some strange issue using jQuery Validation plugin. Firs of all here is

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.