|
> using VC++ 6.0, I trid both a console and win32 project, but your class will not link under either of those project types -- unresolved externals for beginthread and endthread. Linked ok in an ATL/COM project.
change project setting...
project -> setting -> c/c++ tab -> change category , set code generation -> change use run-time library to multithreaded
> also, in your example, what is httpRequest object? If it is supposed to be an GenericHTTPClient object, then where is QueryResponse() method??
GenericHTTPClient httpClient;
if(httpRequest.Request("http://www.codeproject.com")){
LPCTSTR szHTML=httpRequest.QueryResponse();
}else{
LPVOID lpMsgBuffer;
DWORD dwRet=FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
httpRequest.GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
reinterpret_cast<lptstr>(&lpMsgBuffer),
0,
NULL);
MessageBox( reinterpret_cast<lptstr>(lpMsgBuffer), "ERROR", MB_OK);
LocalFree(lpMsgBuffer);
}
this is sample..
if u want received by fixed bytes,
use connect, requestofuri, response.
And, next version is http://gooshin.zzem.net/wiki/index.php/W3Client
------------------------------
http://gooshin.zzem.net
|
|
|
|
|
I'm working the the realms of CE, and there's no SOAP or XMLHTTP API's avialable...
Would it be possible to use this to achieve the desired affect? I know I'll have to be wrap up the message and request into SOAP XML...
Any ideas on how I would do this?
Thanks!
Dan.
|
|
|
|
|
well..
I think that a best way is wrap up the message.
if you make the XMLHTTP or SOAP class with this class,
I think that you will meet many problem.
If you will use class inheritance,
use this class[^].
------------------------------
http://gooshin.zzem.net
|
|
|
|
|
Im using your calls to update a Dynamic DNS, (great class by the way). The DDNS is sending back information (nochg xxx.xxx.xxx.xxx). Am I able to get this? I have tried everything I can think of in you class ...
PLease Help!
Thanks!
MM
|
|
|
|
|
BOOL Response(PBYTE pHeaderBuffer, DWORD dwHeaderBufferLength, PBYTE pBuffer, DWORD dwBufferLength, DWORD &dwResultSize);
LPCTSTR QueryHTTPResponse();
LPCTSTR QueryHTTPResponseHeader();
this method help u that get response.
------------------------------
http://gooshin.zzem.net
|
|
|
|
|
Very nice code, it helped me alot! I have a question about using PostMultiPartsFormData(). Can you explain what it does and why (and when) one should se it?
Thanks,
John
|
|
|
|
|
Do u have been read RFC 1945, 2068?
these explian that HTTP protocol act.
the HTTP POST multipart/form-data transaction is that binary data send to HTTP Server.
if u send file or binary data to http server, you must use it.
thanks.
------------------------------
http://gooshin.zzem.net
|
|
|
|
|
What about RFC1867 ?
Does your class is compatible with it
http://www.faqs.org/rfcs/rfc1867.html
Cheers
Programming is not an end in itself but only a means to an end
|
|
|
|
|
|
I added your class to my vc++ project.
By the way, your class raise compile error.
error message:
w3c.cpp(982) : fatal error C1010: unexpected end of file while looking for precompiled header directive
|
|
|
|
|
Just turn off precompiled headers under project settings; and read this
-> http://www.msoe.edu/eecs/cese/resources/cppbuild/msvcmfc/mfc_err.htm
|
|
|
|
|
sorry if this was asked before, didn't see anything.
I'm building a client program, and I get a 'The server name or address could not be resolved' message.
the relevant code lines are:
establishing connection:
Connection = Session.GetHttpConnection("http://www.google.com/");
sending request and recieving file:
char* c = "/index.html";
CHttpFile* details = TheList->Connection->OpenRequest(0,c);
details->SendRequest();
char* l;
details->ReadString(l,100);
as you can see, I'm trying to connect to google, and I tried other well-known services.
what am I doing wrong?
|
|
|
|
|
'The server name or address could not be resolved',
this message see you don't configure DNS server.
first, you must set DNS server address.
------------------------------
http://gooshin.zzem.net
|
|
|
|
|
thanks
how do I do that?
|
|
|
|
|
Fix function GetPostArguments:
DWORD GenericHTTPClient::GetPostArguments(LPTSTR szArguments, DWORD dwLength){
std::vector<generichttpargument>::iterator itArg;
::ZeroMemory(szArguments, dwLength);
CURLEncode encoder;
for(itArg=_vArguments.begin(); itArg<_vArguments.end(); ){
_tcscat(szArguments, encoder.URLEncode(itArg->szName));
_tcscat(szArguments, "=");
_tcscat(szArguments, encoder.URLEncode(itArg->szValue));
if((++itArg)<_vArguments.end()){
_tcscat(szArguments, "&");
}
}
*(szArguments+dwLength)='\0';
return _tcslen(szArguments);
}
CURLEncode at http://www.codeguru.com/cpp_mfc/URLEncode.html
|
|
|
|
|
|
Your class is very interesting and useful. Do you know how to modify it in order it to work with an HTTPS server?
Julien
|
|
|
|
|
this class next version is here[^]
next version support http/https/ftp.
maybe.. this article will be updated..
thanks
------------------------------
http://gooshin.zzem.net
|
|
|
|
|
Thanks a lot for your class, that works well...
Julien
|
|
|
|
|
m..
I think the new address is:
http://www.codeproject.com/internet/w3client.asp
__________________
Suggestions go to -
http://www.ptez.com/ : Pretty Easy Solutions!
Professional Hosting Service w/ 100GB Bandwidth
|
|
|
|
|
Can this class be used in ATL ?
Are the Bugs reported in the Posts are updated in the download ?
Thanks !
Wonderful effort
|
|
|
|
|
In my case, This class was created for ATL(Active X Server Component).
So, this class will work well done in ATL.
thanks..
------------------------------
http://gooshin.zzem.net
|
|
|
|
|
I found a few instances of CloseHandle in your code. It should have used InternetCloseHandle().
In the GenericHTTPClient::Connect function and GenericHTTPClient::Close. You should also NULL out the handles on closing the handles.
Finally, if you really want this code to be tight, I would recommend changing the functions to explicitly load wininet.dll, vs dynamic loading. Dynamic linking of dlls in a uncontrolled target environment is not a good idea for production grade code. Applications linking in this class will not always function appropriately if the wininet.dll is not installed, or older versions are installed, etc, etc.
Try something like this:
static HINTERNET (WINAPI *f_InternetOpen)(
IN LPCTSTR lpszAgent,
IN DWORD dwAccessType,
IN LPCTSTR lpszProxy OPTIONAL,
IN LPCTSTR lpszProxyBypass OPTIONAL,
IN DWORD dwFlags) = NULL;
static HINTERNET (WINAPI *f_InternetConnect)(
IN HINTERNET hInternet,
IN LPCTSTR lpszServerName,
IN INTERNET_PORT nServerPort,
IN LPCTSTR lpszUsername,
IN LPCTSTR lpszPassword,
IN DWORD dwService,
IN DWORD dwFlags,
IN DWORD_PTR dwContext) = NULL;
static DWORD (WINAPI *f_InternetAttemptConnect)(
IN DWORD dwReserved ) = NULL;
static BOOL (WINAPI *f_InternetCloseHandle)(
IN HINTERNET hInternet) = NULL;
static HINTERNET (WINAPI *f_HttpOpenRequest)(
IN HINTERNET hConnect,
IN LPCTSTR lpszVerb,
IN LPCTSTR lpszObjectName,
IN LPCTSTR lpszVersion,
IN LPCTSTR lpszReferer,
IN LPCTSTR* lpszAcceptTypes,
IN DWORD dwFlags,
IN DWORD_PTR dwContext ) = NULL;
static BOOL (WINAPI *f_HttpAddRequestHeaders)(
IN HINTERNET hConnect,
IN LPCTSTR lpszHeaders,
IN DWORD dwHeadersLength,
IN DWORD dwModifiers ) = NULL;
static BOOL (WINAPI *f_HttpSendRequest)(
IN HINTERNET hRequest,
IN LPCTSTR lpszHeaders,
IN DWORD dwHeadersLength,
IN LPVOID lpOptional,
IN DWORD dwOptionalLength ) = NULL;
static BOOL (WINAPI *f_InternetQueryOption)(
IN HINTERNET hInternet,
IN DWORD dwOption,
OUT LPVOID lpBuffer,
IN LPDWORD lpdwBufferLength ) = NULL;
static BOOL (WINAPI *f_InternetSetOption)(
HINTERNET hInternet,
DWORD dwOption,
LPVOID lpBuffer,
DWORD dwBufferLength ) = NULL;
static BOOL (WINAPI *f_HttpSendRequestEx)(
HINTERNET hRequest,
LPINTERNET_BUFFERS lpBuffersIn,
LPINTERNET_BUFFERS lpBuffersOut,
DWORD dwFlags,
DWORD dwContext ) = NULL;
static BOOL (WINAPI *f_InternetWriteFile)(
HINTERNET hFile,
LPCVOID lpBuffer,
DWORD dwNumberOfBytesToWrite,
LPDWORD lpdwNumberOfBytesWritten ) = NULL;
static BOOL (WINAPI *f_HttpEndRequest)(
HINTERNET hRequest,
LPINTERNET_BUFFERS lpBuffersOut,
DWORD dwFlags,
DWORD dwContext ) = NULL;
static BOOL (WINAPI *f_InternetReadFile)(
IN HINTERNET hFile,
IN LPVOID lpBuffer,
IN DWORD dwNumberOfBytesToRead,
OUT LPDWORD lpdwNumberOfBytesRead) = NULL;
static BOOL (WINAPI *f_HttpQueryInfo)(
IN HINTERNET hRequest,
IN DWORD dwInfoLevel,
IN OUT LPVOID lpBuffer OPTIONAL,
IN OUT LPDWORD lpdwBufferLength,
IN OUT LPDWORD lpdwIndex OPTIONAL) = NULL;
static HMODULE wininet = NULL;
static int InitWinInet(void)
{
wininet = LoadLibrary("wininet.dll");
if (!wininet)
{
return -1;
}
CPPASS f_InternetOpen = GetProcAddress(wininet, "InternetOpenA");
CPPASS f_InternetConnect = GetProcAddress(wininet, "InternetConnectA");
CPPASS f_InternetAttemptConnect = GetProcAddress(wininet, "InternetAttemptConnect");
CPPASS f_InternetCloseHandle = GetProcAddress(wininet, "InternetCloseHandle");
CPPASS f_HttpOpenRequest = GetProcAddress(wininet, "HttpOpenRequestA");
CPPASS f_HttpAddRequestHeaders = GetProcAddress(wininet, "HttpAddRequestHeadersA");
CPPASS f_HttpSendRequest = GetProcAddress(wininet, "HttpSendRequestA");
CPPASS f_InternetQueryOption = GetProcAddress(wininet, "InternetQueryOptionA");
CPPASS f_InternetSetOption = GetProcAddress(wininet, "InternetSetOptionA");
CPPASS f_HttpSendRequestEx = GetProcAddress(wininet, "HttpSendRequestExA");
CPPASS f_InternetWriteFile = GetProcAddress(wininet, "InternetWriteFile");
CPPASS f_HttpEndRequest = GetProcAddress(wininet, "HttpEndRequestA");
CPPASS f_InternetReadFile = GetProcAddress(wininet, "InternetReadFile");
CPPASS f_HttpQueryInfo = GetProcAddress(wininet, "HttpQueryInfoA");
if ( !f_InternetOpen ||
!f_InternetConnect ||
!f_InternetAttemptConnect ||
!f_InternetCloseHandle ||
!f_HttpOpenRequest ||
!f_HttpAddRequestHeaders ||
!f_HttpSendRequest ||
!f_InternetQueryOption ||
!f_InternetSetOption ||
!f_HttpSendRequestEx ||
!f_InternetWriteFile ||
!f_HttpEndRequest ||
!f_InternetReadFile ||
!f_HttpQueryInfo )
{
return -2;
}
return 0;
}
void UnloadWinInet()
{
if (wininet)
FreeLibrary(wininet);
wininet = NULL;
}
Finally, I thing your sample is excellent. I would make two other ammendments, per some of the suggestions:
1. Add HTTPS support
2. Add custom content types
(remove underscores to retrieve my email address).
k_e_i_t_h@p_i_r_k_l_s.com
|
|
|
|
|
Has anyone tried to use this sample with Unicode? I have some apprehensions, though apparently the code seems to be Unicode.
At many places the TEXT / _T macro is missing?
Anyways the code is nicely written!!! Cheers..
- SUDESH SAWANT
Bond with the best
|
|
|
|
|
When I set the project with Unicode, and replace the string with TEXT / _T, it still compile error. The error is in HttpOpenRequest().
=============================================
The original code is:
CONST TCHAR *szAcceptType=__HTTP_ACCEPT_TYPE;
_hHTTPRequest=::HttpOpenRequest( _hHTTPConnection,
__HTTP_VERB_GET, // HTTP Verb
szURI, // Object Name
HTTP_VERSION, // Version
_T(""), // Reference
&szAcceptType, // Accept Type
INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_NO_CACHE_WRITE,
0); // context call-back point
=============================================
Fix:
LPTSTR AcceptTypes[2]={0};
AcceptTypes[0]=__HTTP_ACCEPT_TYPE;
_hHTTPRequest=::HttpOpenRequest( _hHTTPConnection,
__HTTP_VERB_GET, // HTTP Verb
szURI, // Object Name
HTTP_VERSION, // Version
_T(""), // Reference
(LPCTSTR*)AcceptTypes, // Accept Type
INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_NO_CACHE_WRITE,
0); // context call-back point
chilan
|
|
|
|
|