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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:59:59+00:00 2026-06-10T04:59:59+00:00

I’m basically sending a post to my server. The string I’m writing is @POST

  • 0

I’m basically sending a post to my server. The string I’m writing is @”POST /api?f=### HTTP/1.1\r\nHost: http://server.loc.a.tion\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: ##\r\n\r\ndata=somedataandstuff”. After this the server is supposed to send me back a message. (not that I’ve got that far yet.)

I’m following the basic polling code as lined out by apple, but I’ve made some changes.

Note the following is after I’ve opened the streams), data_to_send.buffer is a (char *), and data_to_send.buffer_size is 1500.

//Preform Write operations
bool done = false;
int bufLen = data_to_send.buffer_size;
const uint8_t * rawstring =(const uint8_t *)data_to_send.buffer;
CFIndex bytesWritten;
while (!done) {
    CFStreamStatus stat = CFWriteStreamGetStatus(writeStream); //for me while debugging
    if (CFWriteStreamCanAcceptBytes(writeStream)) {

        //ADDED:
        if(bufLen > 0)  bytesWritten = CFWriteStreamWrite(writeStream, rawstring, (CFIndex)bufLen);

        //ADDED: to check if it ever writes
        if( CFWriteStreamGetStatus(writeStream) == kCFStreamStatusWriting){
            NSLog(@"lalallaa");
        }

        if (bytesWritten < 0) {
            //error stuff
        } else if (bytesWritten == 0) {
            if (CFWriteStreamGetStatus(writeStream) == kCFStreamStatusAtEnd) {
                done = TRUE;
                rawstring = nil;
            }
        } else if (bytesWritten != bufLen) {
            // Determine how much has been written and adjust the buffer
            bufLen = bufLen - bytesWritten;
            memmove(rawstring, rawstring + bytesWritten, bufLen);

            //error stuff
        } else {  //ADDED
            bufLen = 0;
            bytesWritten = 0;
            //loop and wait until finished
        }

    }
}
CFWriteStreamClose(writeStream);
CFRelease(writeStream);
writeStream = NULL;

I modified the code because CFWriteStreamWrite returns the full 1500 (this is a flag in my mind: if bufLen is 1500 and it writes it all shouldn’t it return 0?), which wasn’t accounted for in apples code (ie: bytesWritten == bufLen)(another flag as I assume apple wouldn’t miss anything unless this was the intended functionality). In turn the bufLen or the buffer (rawstring) don’t get modified and we just repeatedly return 1500, and commence a never ending cycle. So to account for this I added the else which sets bufLen to 0 and bytes written to 0 so that the code will loop to check when it reaches KCFStreamStatusAtEnd. Now when I step through this I noticed that once it does CFWriteStreamWrite the status is till 2 (CFStreamStatusOpen) and hence another never ending cycle. The check I added to see if it ever writes never gets hit so as far as I can tell it doesn’t.

But, now if we check the apache access log on the server we have:

… “-” 408 –

where a working call (made from working java code) would look like

… “POST /api?f=blahblah” 200 ##

so I feel like something is at least trying to be written. Although a 408 status is a Request times out. This could be because the stream sits there while I debug with the stream open? Or because when I debug and stop I never close the stream?

Any ideas or suggestions would be greatly appreciated. (I’m new to iOS/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-06-10T05:00:01+00:00Added an answer on June 10, 2026 at 5:00 am

    If anyone is interested in this I basically gave up and went with a NSMutableURLrequest.

    NSString *urlString = @"http://url.ca/api?f=##";
    NSMutableURLrequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
    [request setHTTPMethod:@"POST"];
    [request setValue:@"##" for HTTPHeaderField@"Contect-Length"];
    [request setValue:@"application/x-www-form-urlencoded" for HTTPHeaderField@"Content-Type"];
    [request setHTTPBody:@"data=lalalalala" dataUsingEncoding:NSASCIIStringEncoding]];
    
    NSURLResponse *response;
    NSError *err;
    NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
    
    //error check & handle data
    

    Keep in mind if you want to do something similar that this is synchronous so it will delay your UI (so run in it’s own thread or do asynchronously). This basically does the same thing that I was trying to code.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
Specifically, suppose I start with the string string =hello \'i am \' me And

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.