http请求

来源:互联网 发布:艾科特餐饮软件 编辑:程序博客网 时间:2024/06/06 02:33

http 获取

// HttpPost.cpp written by l_zhaohui@163.com// 2007/11/30#include "stdafx.h"#include <windows.h>#include <stdio.h>#include <stdlib.h>#include<windows.h>   #include<wininet.h>   //#include<iostream.h>   #pragma comment(lib,"wininet.lib")  #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS#include <atlbase.h>#include <atlstr.h>//#define USE_WINHTTP    //Comment this line to user wininet.#ifdef USE_WINHTTP//#include <winhttp.h>//#pragma comment(lib, "winhttp.lib")#else#include <wininet.h>#pragma comment(lib, "wininet.lib")#endif#define BUF_SIZE    (10240)// CrackedUrl// CrackedUrlint HttpRequest1(){//CHttpClient conn;//// : PostData : "name=Java&password=200199" : Variant/String////   : sRequestURL : "http://61.234.170.173/index.php?module=user&action=login" : String//CString value;////conn.addParam("module", "user");////conn.addParam("action", "login");//conn.addParam("name", "Java");//conn.addParam("password", "200199");//value = conn.doPost("http://61.234.170.173/index.php?module=user&action=login");//OutputDebugString("---HttpRequest---");//AfxMessageBox(value);//OutputDebugString("---HttpRequest end---");return 0;}int HttpRequest(){ HINTERNET hSession = ::InternetOpen("MSDN SurfBear ",INTERNET_OPEN_TYPE_PRECONFIG,NULL,0,0);// Connect to api2.inkever.com:8008 INTERNET_DEFAULT_HTTP_PORT#define OBJWEB "api2.inkever.com"#define HTTPPORT 8008HINTERNET hConnect = ::InternetConnect(hSession, OBJWEB, HTTPPORT, 0, 0, INTERNET_SERVICE_HTTP, 0, 0);// Request the file /MSDN/MSDNINFO/ from the server.DWORD dwFlag = INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_NO_AUTO_REDIRECT | INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_NO_COOKIES;HINTERNET hHttpFile = ::HttpOpenRequest(hConnect, "GET", "/real/1/", "HTTP/1.1", 0, 0, dwFlag, 0);// Send the request.BOOL bSendRequest = ::HttpSendRequest(hHttpFile, NULL, 0, 0, 0);// Get the length of the file.char bufQuery[32];DWORD dwLengthBufQuery = sizeof(bufQuery);BOOL bQuery = ::HttpQueryInfo(hHttpFile, HTTP_QUERY_CONTENT_LENGTH, bufQuery, &dwLengthBufQuery, NULL);int error = GetLastError();// Convert length from ASCII string to a DWORD.DWORD dwFileSize = 100000;//(DWORD)atol(bufQuery);// Allocate a buffer for the file.char* buffer = new char[dwFileSize + 1];// Read the file into the buffer.DWORD dwBytesRead;BOOL bRead = ::InternetReadFile(hHttpFile,buffer,dwFileSize + 1,&dwBytesRead);// Put a zero on the end of the buffer.buffer[dwBytesRead] = 0;AfxMessageBox(buffer); return 0;}


0 0
原创粉丝点击