I just made stackoverflow account because I'm having serious troubles sending multipart/form-data using my C application. There are many libraries I could use to send but for educational purposes I am doing it all from scratch so please bear with me.
The issue is that when I send the request using my application, the server happens to return 400 Bad Request
. I saw this similar question here on stackoverflow and I am unable to fix the request nonetheless. Below is the request I have and a screenshot of what is returned from the server.
screenshot of program when run
// this is the temp_send which is incomplete
// adds the post data later
char *temp_send="POST http://localhost/france/test.php HTTP/1.1
"
"Host: localhost
"
"Accept: image/gif, image/jpeg, */*
"
"Accept-Language: en-us
"
"Content-Type: multipart/form-data; boundary=---------------------------7d41b838504d8
"
"Accept-Encoding: gzip, deflate
"
"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
"
"Connection: keep-alive
"
"Cache-Control: no-cache
"
"---------------------------7d41b838504d8 Content-Disposition: form-data; name=\"name\"
"
"%s
"
"---------------------------7d41b838504d8--
";
char *postdata="testval";
char *sendbuf=NULL;
sendbuf=(char*)malloc(sizeof(char)*SENDLEN);
sprintf(sendbuf, temp_send, postdata);
NOTE: Somehow the "testval" is returned in the <pre>
tags but I need the error to go away. I realize this is a broad question but I just need to narrow down the sending of multipart/form-data.
NOTE 2: I also know that I can use application/x-www-form-urlencoded
and I have already used it and it works but since I will be doing file uploads which are much more complex, I need to use multipart-form/data
and I'm trying with simple plain text first to reduce complexity