Fixed and working...
Code:
#include <stdio.h>
#include <windows.h>
#include <wininet.h>
int main(void) {
char url[] = "upload.php?name=value";
char contenttype[] = "content-type: multipart/form-data; "
"boundary=-----------------------------23281168279961\r\n";
char body[1024] = "-------------------------------23281168279961\r\n"
"content-disposition: form-data; name=\"file\"; filename=\"test.txt\"\r\n"
"content-type: text/plain\r\n"
"\r\n"
"these line is in test.txt that should be uploaded. this line is my file's content"
"\r\n"
"-------------------------------23281168279961"
"\r\n";
HINTERNET hSession = InternetOpen("",INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if (!hSession) {
fprintf(stderr, "InternetOpen failed.\r\n");
return -1;
}
HINTERNET hConnect = InternetConnect(hSession, "localhost",INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1);
if (!hConnect) {
fprintf(stderr, "InternetConnect failed.\r\n");
return -1;
}
HINTERNET hRequest = HttpOpenRequest(hConnect, "POST", url, "HTTP/1.0", NULL, (const char**)"*/*", 0, 0);
if (!hRequest) {
fprintf(stderr, "InternetRequest failed.\r\n");
return -1;
}
if (!HttpAddRequestHeaders(hRequest, contenttype, strlen(contenttype), 0)) {
fprintf(stderr, "HttpAddRequestHeaders failed.\r\n");
fprintf(stderr, "Error: %i", GetLastError());
return -1;
}
if (!HttpSendRequest(hRequest, NULL, 0, body, strlen(body))) {
fprintf(stderr, "HttpSendRequest failed.\r\n");
fprintf(stderr, "Error: %i", GetLastError());
}
InternetCloseHandle(hSession);
InternetCloseHandle(hConnect);
InternetCloseHandle(hRequest);
return 0;
}