Shame on myself for this one....



  • I seriously think I was drunk when I wrote this code.....
    WTF_Http::Post sends a POST request, put the response in szBuffer, which is NOT null terminated, and returns the length of the response in snRespLength.
    (Yeah, I'm the guy who posted in favor of hungarian notation several months back.  I've changed my mind)
    Anyhow, here's my code to do the request and turn it into a string object.... (my company's name replaced with "WTF")


        char* szResponse=NULL;
        unsigned snRespLength=0;
        
        WTF_Http oHttp;
        WTF_String sResponse="";
        
        oHttp.Post(sUrl, GetTimeout(), sReq, &szResponse, &snRespLength);
            
        char* szResponse2 = new char[snRespLength+1];
        memcpy(szResponse2, szResponse, snRespLength);
        szResponse2[snRespLength]=0;
        
        if(szResponse){
            sResponse = szResponse;
            free(szResponse);        
        }
                   
        return sResponse;


    Oddly enough, this didn't explode for OVER A YEAR in a test environment.



  • @vt_mruhlin said:

    I seriously think I was drunk when I wrote this code.....

     

    Hey! Stop drunk bashing!  I code best when my BAC >= .30



  • @MyWillysWonka said:

    @vt_mruhlin said:

    I seriously think I was drunk when I wrote this code.....

     

    Hey! Stop drunk bashing!  I code best when my BAC >= .30

    Back in college, I used to drink while coding.  Usually ended up being officially drunk once it came time to debug, and the drunkenness really made me a better debugger.  So one time I decided to get drunk before starting the code.  That didn't work out so well.
     



  • @vt_mruhlin said:

    Back in college, I used to drink while coding.  Usually ended up being officially drunk once it came time to debug, and the drunkenness really made me a better debugger.

    It works - it just doesn't bother you anymore, that you're stepping through the same function for the 678732483'th time, but in different conditions. ;)


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.