Oct 14, 2011 at 12:24pm UTC
Hi everybody,
I'm programming in C and I'd like to make a POST request to download a file. But I'm not sure how should I insert the content of my file.
Header :
POST ip:port/page.php HTTP/1.0
content-type: multipart/form-data, boundary=AasF4gs8gDqH5JB0x
content-length: 12345
strcpy(body, "--AasF4gs8gDqH5JB0x\r\n");
strcat(body, "content-disposition: form-data; name=\"myfile\"; filename=\"myfile.ext\"\r\n");
strcat(body, "content-type: application/octet-stream\r\n");
strcat(body, "content-transfer-encoding: binary\r\n");
strcat(body, "\r\n");
// Here if I well understood I must put the content of "myfile.ext"
// I thought tu put the result of a fread() inside a char* and to concat it to the body but I can't
strcat(body, "--AasF4gs8gDqH5JB0x--");
So is possible to put a binary code and char* inside the same string ? Or is there a better method ?
Thank you for your help.
Last edited on Oct 14, 2011 at 12:24pm UTC
Oct 14, 2011 at 5:20pm UTC
Yes, you can, but you cannot use strXXX APIs because the binary file's content is not C string.
You can use any methods(read, fread) that can read binary file to directly read the file's content to the memory pointed by body + strlen(body).
Or if the file's content has been read into the memory, just use memcpy() to copy the content to body + strlen(body)
Last edited on Oct 14, 2011 at 5:20pm UTC