 |
|
 |
How do i use sessions with this client? What i have is a login page that redirects me to an upload page
|
|
|
|
 |
|
 |
sessions are Server's Values.
after connect your server, if you have don't close(), you should be use sessions.
good luck.
|
|
|
|
 |
|
 |
W3Client w3;
CString szheader;
CString szsource;
w3.SetAskInstallCert(m_bAskInstallCert);
if(w3.Connect((const char*)m_sUrl)){
if(w3.Request(w3.GetURI())){
unsigned char buf[1024]="\0";
unsigned char buf2[1025]="\0";// 1025 is "\0"
w3.QueryRawHeader(buf, 1024);
szheader=buf;
memset(buf, 0x00, 1024);
int read = 0;
while(read = w3.Response(buf, 1024)){
memset(buf2, 0x00, 1025);
memset(buf2, 65, read);
szsource+=buf2;
memcpy(szsource.GetBuffer(szsource.GetLength()) + szsource.GetLength() - read, buf, read);
memset(buf, 0x00, 1024);
}
HANDLE file=(HANDLE)::CreateFile(m_sFileDownload, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
unsigned long nw=0;
WriteFile(file, (const char*)szsource, szsource.GetLength(), &nw, NULL);
::CloseHandle(file);
}
w3.Close();
}
--------------------------
ERP VN: www.erpvn.net
|
|
|
|
 |
|
 |
Sorry but the #include header: afx.h, necessary for CString is sucks! the original exe generated file length is more less 195KB (so big but respetable) if we include your code sounds around 1.30 MB, so this is so big implementation for a single use of buffering on CString.
so, i change your code unless afx.h and his result length is 138 KB (1 MB less)
so, here the code:
usage:
{HOST} {REMOTE_FILE} {LOCAL_FILE}
if(w3.Connect(argv[1])){
if(w3.Request(argv[2])){
unsigned char buf[1024]="\0";
w3.QueryRawHeader(buf, 1024);
memset(buf, 0x00, 1024);
int read = 0;
HANDLE file=(HANDLE)::CreateFile(argv[3], GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
unsigned long nw=0;
while(read = w3.Response(buf, 1024)){
WriteFile(file, buf, read, &nw, NULL);
memset(buf, 0x00, 1024);
}
::CloseHandle(file);
}
w3.Close();
}
return 0;
unless the fatty exe than thin exe!
cheers
dark_alex
|
|
|
|
 |
|
 |
Hello,
I am new in WWW programming. I am trying to post xml data to a web server with your useful class, but I have some problems using the W3Client::RequestPost2 method. I wrote xml data into a file, but I cannot send the file to the server. The server always replay with this:
falseunsupportedMediaType
I also used Ethereal SW to trace the ethernet packets and it seems that in the packets there is no data belonging to the file containing the xml data.
For sure I am doing something wrong. Could you please help me in understanding what is going wrong ?
Thank you in advance for your help
Best regards
tino55
|
|
|
|
 |
|
 |
Hello, there.
I have a question.
I try to update a jpeg file(3kb)
upload is succeeded...
but...
the origin file is different to uploaded file.
Origin : FF D8 FF E0 00 10 4A 46 49 46 00 01 02 00 00 64 ; ??.JFIF.....d
Uploaded : (10 bytes missed..) 00 01 02 00 00 64
Why?
let me know, what i mistake...
please~
Best regards,...
------------------
Yail Kim
|
|
|
|
 |
|
 |
maybe,. i seem that this problem is your mistake.
^^
|
|
|
|
 |
|
 |
hi greate class
i just downloaded it 10 min ago so i havent realy look into it but i understand that the AddPostArgument(...) dose encode the string to url encoding correct ? is there a way not doing it ? for example if i want to pass the string "mail@mail.com" it seemes to scru it up.
thank you
|
|
|
|
 |
|
 |
well,. when i make this class, i leave a matter out of consideration that url encoding.
if u want url encode, use follow :
#define HEXCHAR(v) ((v) < 10 ? (v) + '0' : (v) - 10 + 'A')
LPSTR URLEncode(LPCTSTR szValue){
LPSTR szEncoded=new CHAR[strlen(szValue)*3+1];
LPSTR szWrite=szEncoded;
BYTE ch;
while ((ch = *szValue)){
if (!isalnum(ch)){
*szWrite++ = '%';
*szWrite++ = HEXCHAR(ch >> 4);
*szWrite++ = HEXCHAR(ch & 0x0F);
}else
*szWrite++ = ch;
++szValue;
}
*szWrite = '\0';
return szEncoded;
}
good luck
|
|
|
|
 |
|
 |
First of all, thank you for developen the class-it's very useful
I need to upload file (HTTP) using form. Since the files may be pretty large, I would need to get some feedback of the progress.
How can I do this?
Thanks a lot.
|
|
|
|
 |
|
 |
maybe, if supported "keep-alive", so you should be received notify by asynchronized http connection on call-back function.
wininet library support callback-function that named "INTERNET_STATUS_CALLBACK" for status receive.
good luck.
|
|
|
|
 |
|
 |
Hi,
Did you manage to do progress in uploading....
I really need help....
Regards
Marlon
|
|
|
|
 |
|
 |
Hi,
I managed to do this....
All you have to do is to pass the callback function in every step before sending the request
hRequest = HttpOpenRequest( hConnection, _T("POST"), (LPCTSTR)this->scriptName.c_str(), NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, (INTERNET_STATUS_CALLBACK)progressCounter );
Regards
Marlon
|
|
|
|
 |
|
 |
Are you sure you can pass a function pointer there? As I see it, this function accpts a DWORD as parameter.
|
|
|
|
 |
|
 |
1) Bug Description.
When I have my connexion internet offline, if I call the function Connect(..), the program crash.
When I have my connexion internet online, the return value of the function Connect(..) is always true.
2) To fix this bug.
In the file w3c.cpp
Change the following line (TWICE)
::CloseHandle(_hConnection);
by
::InternetCloseHandle(_hConnection);
And change the following line (TWICE)
::CloseHandle(_hOpen);
by
::InternetCloseHandle(_hOpen);
AlanLive
|
|
|
|
 |
|
 |
First, thanks for the great article and code. I've learned a lot from it.
But, I think I see a bug in the async client. It isn't necessarily waiting on the handles to be created.
Check out this MSDN link:
http://www.kbalertz.com/kb_Q275046.aspx[^]
One of the bullet points states:
>>>For asynchronous calls that return handles, you must wait for the INTERNET_STATUS_HANDLE_CREATED notification to get the value of the handle that has been created for you. When you receive this notification, save the handle value from the INTERNET_ASYNC_RESULT structure's dwResult member. You cannot use this handle until you have received the INTERNET_STATUS_REQUEST_COMPLETE notification.
Looking at the AsyncW3Client, it doesn't wait for the INTERNET_STATUS_HANDLE_CREATED message:
CAsyncW3Client::Connect() {
...
_hConnection=::InternetConnect(...);
if(!_hConnection || _hConnection==INVALID_HANDLE_VALUE)
throw "connect failed...";
According to MSDN, it isn't safe to immediately check the _hConnection. You have to wait until INTERNET_STATUS_HANDLE_CREATED is received in the StatusCallback (registered via InternetSetStatusCallback).
Apparently, to fix this, you'll have to SetEvent in the callback and in the Connect() you need to WaitForSingleObject() before checking _hConnection, for example:
_hConnection=::InternetConnect(...);
if (hConnect == NULL)
{
if (GetLastError() != ERROR_IO_PENDING)
WaitForSingleObject(hConnectedEvent, INFINITE); // Event set when call receives INTERNET_STATUS_HANDLE_CREATED
}
if(!_hConnection || _hConnection==INVALID_HANDLE_VALUE)
throw "connect failed...";
Thanks,
Dean
|
|
|
|
 |
|
 |
Hello everyone,
I like this application and I would love to use it. I type into the window https://myclient.php and the application does not get through to the server. I don't know if I am doing something wrong or if there is something in the code that I need to change. Please let me know because I would love to use this application for HTTPS. Thanks. Zeljko
|
|
|
|
 |
|
 |
Add server certificate to certificate trusted root.
|
|
|
|
 |
|
 |
Comment this lines:
/*
DWORD dwStatus = m_pEncrypt->VerifyServerCertificate(pchServerName, INTERNET_FLAG_IGNORE_CERT_CN_INVALID);
if (dwStatus != SEC_E_OK)
{
...
*/
|
|
|
|
 |
|
 |
Hey, there isn't these lines. do U hide this like where?
|
|
|
|
 |
|
 |
I am using SSL library from platform SDK:
..\Microsoft Platform SDK\Samples\WinBase\Security\SSL
TomazZ
|
|
|
|
 |
|
 |
Use this link to solve https problem:
http://support.microsoft.com/kb/q182888/
BR
Zsolt
|
|
|
|
 |
|
 |
When i go to above link, i did follow code in that link, but it get error with error code = 10035
--------------------------
ERP VN: www.erpvn.net
|
|
|
|
 |
|
 |
I modified that code below:
int times = 0;
DWORD dwError = 0;
Again:
// SEND REQUEST
if(!::HttpSendRequest( _hRequest, // handle by returned HttpOpenRequest
NULL, // additional HTTP header
0, // additional HTTP header length
NULL, // additional data in HTTP Post or HTTP Put
0) // additional data length
)
{
// James modified
dwError = ::GetLastError();
times++;
if (times < 10)// && dwError == ERROR_INTERNET_INVALID_CA)
{
if (_bAskInstallCert) // Show Dlg
{
DWORD dwNetErr = 0;
// Make sure to check return code from InternetErrorDlg
// user may click either OK or Cancel. In case of Cancel
// request should not be resumbitted.
dwNetErr = InternetErrorDlg (GetDesktopWindow(),
_hRequest,
//ERROR_INTERNET_INVALID_CA,
dwError,
FLAGS_ERROR_UI_FILTER_FOR_ERRORS |
FLAGS_ERROR_UI_FLAGS_GENERATE_DATA |
FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS,
NULL);
switch(dwNetErr){
case ERROR_INTERNET_FORCE_RETRY:
printf("Interne force retry\n");
break;
case ERROR_CANCELLED:
printf("Cancelled\n");
times = 10; // Stop
break;
case ERROR_SUCCESS:
printf("Success\n");
break;
}
goto Again;
}
else // without Dlg
{
DWORD dwNetErr = 0;
DWORD dwFlags;
DWORD dwBuffLen = sizeof(dwFlags);
InternetQueryOption (_hRequest, INTERNET_OPTION_SECURITY_FLAGS,
(LPVOID)&dwFlags, &dwBuffLen);
dwFlags |= SECURITY_FLAG_IGNORE_UNKNOWN_CA | SECURITY_FLAG_IGNORE_CERT_CN_INVALID ;
if ( !InternetSetOption (_hRequest, INTERNET_OPTION_SECURITY_FLAGS,
&dwFlags, sizeof (dwFlags) ) )
printf("Set Option failed errcode: %ld\n", GetLastError());
goto Again;
}
}
--------------------------
ERP VN: www.erpvn.net
|
|
|
|
 |
|
 |
:-OSet the W3Client::w3https W3Client::reqPost in your code as follow:
client.Connect("ServerName",Port,NULL,NULL,W3Client::w3https);
client.Request("ObjFile", W3Client::reqPost)
|
|
|
|
 |