OiO.lk Blog C# Http post cannot find boundary in the end
C#

Http post cannot find boundary in the end


I am now implementing an easy http server in C, and I need to deal with request that posts a video file. I am now encountering a problem. After I extract the boundary in the message, I can use strstr() function to detect the boundary in front of video content, however, it failed to detect the boundary behind video content(it returned NULL, and I can find the boundary in the written file after executing the code). Codes of reading video content (header is extracted beforehand) and detect boundary are below. Thanks for help!

int fla = 0;
 while(endoffile == NULL){                                                    
        memset(buf, 0, BUFFERSIZE);
        int re;
        re = read(i,buf,BUFFERSIZE);
        if(re <= 0 && fla == 0){
              fla = 1;
              continue;
         }
        if(re <= 0 && fla == 1){
              break;
        }
        if(re > 0 && fla == 1){
              fla = 0;
        }
        num_read += re;
        endoffile = strstr(buf,boundaryarr);
        if(endoffile == NULL){
            write(newfd,buf,BUFFERSIZE);
        }else{
            endoffile -= 3;
            *endoffile="\0";
            write(newfd,buf,BUFFERSIZE);
            close(newfd);
        }
 }

I have tried printing the buffer out, I cannot find the boundary as well(I guess that coding the video file affects the boundary). However, the boundary showed up in the written file after executing the code.



You need to sign in to view this answers

Exit mobile version