【小记备忘】之Winnet调用webservice【2013.12.23】
发布时间:2020-12-16 23:55:40 所属栏目:安全 来源:网络整理
导读:【小记备忘】之Winnet调用webservice【2013.12.23】 欢迎加入我们的QQ群,无论你是否工作,学生,只要有c / vc / c++ 编程经验,就来吧! 158427611? #include "stdafx.h"#include windows.h#include wininet.h//#import "Wininet.lib"static TCHAR* g_lpszS
【小记备忘】之Winnet调用webservice【2013.12.23】 欢迎加入我们的QQ群,无论你是否工作,学生,只要有c / vc / c++ 编程经验,就来吧!158427611? #include "stdafx.h" #include <windows.h> #include <wininet.h> //#import "Wininet.lib" static TCHAR* g_lpszSOAPRequest = _T("<soap:Envelope ") _T("xmlns:n='urn:xmethods-Temperature' ") _T("xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' ") _T("xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/' ") _T("xmlns:xs='http://www.w3.org/2001/XMLSchema' ") _T("xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'> ") _T("<soap:Body soap:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'> ") _T(" <n:getTemp> ") _T(" <zipcode xsi:type='xs:string'>98007</zipcode> ") _T(" </n:getTemp> ") _T("</soap:Body> ") _T("</soap:Envelope>"); #define CHUNK_SIZE 2048 int CallWebService(); int _tmain(int argc,_TCHAR* argv[]) { CallWebService(); return 0; } int CallWebService() { HINTERNET hSession = ::InternetOpen(_T("SoapTrans"),INTERNET_OPEN_TYPE_PRECONFIG,_T(""),INTERNET_INVALID_PORT_NUMBER,0); if(hSession == NULL) { return 0; } HINTERNET hConnect = ::InternetConnect(hSession,_T("localhost"),NULL,INTERNET_SERVICE_HTTP,0); if(hConnect == NULL) { ::InternetCloseHandle(hSession); return 0; } HINTERNET hHttpFile = ::HttpOpenRequest(hConnect,_T("POST"),_T("/WebService....."),HTTP_VERSION,INTERNET_FLAG_DONT_CACHE,0); if(hHttpFile == NULL) { ::InternetCloseHandle(hConnect); ::InternetCloseHandle(hSession); return 0; } BOOL bSendRequest = ::HttpSendRequest(hHttpFile,-1,g_lpszSOAPRequest,strlen(g_lpszSOAPRequest)); if(bSendRequest) { { char achQueryBuf[16]; DWORD dwFileSize; DWORD dwQueryBufLen = sizeof(achQueryBuf); BOOL bQuery = ::HttpQueryInfo(hHttpFile,HTTP_QUERY_CONTENT_LENGTH,achQueryBuf,&dwQueryBufLen,NULL); if(bQuery) { dwFileSize = (DWORD)atol(achQueryBuf); char* response = new char[dwFileSize]; DWORD dwLength; BOOL bGet = ::InternetReadFile(hHttpFile,response,dwFileSize,&dwLength); printf(response); } } ::InternetCloseHandle(hHttpFile); ::InternetCloseHandle(hConnect); ::InternetCloseHandle(hSession); } } 158427611? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |