Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _WIN32_WINNT 0x0500
- #include <windows.h>
- #include <wininet.h>
- #include <tchar.h>
- #include <iostream>
- #include <string.h>
- #include <fstream>
- #include <cstdlib>
- #pragma comment(lib,"wininet.lib")
- using namespace std;
- void envia(){
- int length;
- char * buffer;
- ifstream is;
- is.open ("imagem.jpg", ios::binary );
- is.seekg (0, ios::end);
- length = is.tellg();
- is.seekg (0, ios::beg);
- buffer = new char [length];
- is.read (buffer,length);
- is.close();
- string conteudo;
- conteudo ="-----------------------------7d82751e2bc0858\nContent-Disposition: form-data; name=\"file\"; filename=\"imagem.jpg\"\nContent-Type: text/plain\n\n";
- conteudo += buffer ;
- conteudo += "\n-----------------------------7d82751e2bc0858--" ;
- TCHAR *param=new TCHAR[conteudo.size()+1];
- param[conteudo.size()]=0;
- std::copy(conteudo.begin(),conteudo.end(),param);
- static TCHAR hdrs[] = "Content-Type: multipart/form-data; boundary=---------------------------7d82751e2bc0858";
- HINTERNET hSession = InternetOpen("MyAgent",INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
- if (!hSession)
- {
- printf(" (!) hSession failed!\n");
- }
- HINTERNET hConnect = InternetConnect(hSession,("meusite.com.br"),INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1);
- if (!hConnect)
- {
- printf(" (!) hConnect failed!\n");
- }
- HINTERNET hRequest = HttpOpenRequest(hConnect, (const char*)"POST",_T("erros/glauco/upload.php"), NULL, NULL, (const char**)"*/*\0", 0, 1);
- if (!hRequest)
- {
- printf(" (!) Ocorreu um erro de numero %d!\n",GetLastError());
- InternetCloseHandle(hSession);
- InternetCloseHandle(hConnect);
- InternetCloseHandle(hRequest);
- }
- BOOL sent= HttpSendRequest(hRequest,
- hdrs,
- strlen(hdrs),
- param,
- strlen(param));
- printf(" >>> Enviado Com sucesso!! \n");
- InternetCloseHandle(hSession);
- InternetCloseHandle(hConnect);
- InternetCloseHandle(hRequest);
- }
- void ReadFile(char *name)
- {
- FILE *file;
- char *buffer;
- unsigned long fileLen;
- //Open file
- file = fopen(name, "rb");
- if (!file)
- {
- fprintf(stderr, "Unable to open file %s", name);
- return;
- }
- //Get file length
- fseek(file, 0, SEEK_END);
- fileLen=ftell(file);
- fseek(file, 0, SEEK_SET);
- //Allocate memory
- buffer=(char *)malloc(fileLen+1);
- if (!buffer)
- {
- fprintf(stderr, "Memory error!");
- fclose(file);
- return;
- }
- //Read file contents into buffer
- fread(buffer, fileLen, 1, file);
- fclose(file);
- //Do what ever with buffer
- free(buffer);
- }
- int main(int argc, char *argv[])
- {
- //envia();
- system("PAUSE");
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement