 |
|
 |
You must call GetHeaders(url) before GetPageStatusCode(). If not, the "Headers" variable is empty and GetPageStatusCode() depend on it.
But take care, GetHeaders use InternetOpenUrl(...) with NO header, so the server can reject the request.
|
|
|
|
 |
|
 |
modify GetHeaders()
delete these codes
if (url == NULL)
{
LastError = -1;
return NULL;
}
add code in PostUrl(.)
if (hIS != NULL)GetHeaders();
is ok
|
|
|
|
 |
|
 |
I'm finding some issues...
First, if I use like this :
char *s = http.GetPage(_T("http://somewebpage/", true, "?Username=SomeUser&Password=SomePassword&Otherdata=SomeMoreData");
I can't compile :
----------------------
--------------------Configuration: ValidaLogin - Win32 Debug--------------------
Compiling...
ValidaLoginDlg.cpp
C:\Arquivos de programas\Microsoft Visual Studio\MyProjects\ValidaLogin\ValidaLoginDlg.cpp(184) : warning C4002: too many actual parameters for macro '_T'
C:\Arquivos de programas\Microsoft Visual Studio\MyProjects\ValidaLogin\ValidaLoginDlg.cpp(184) : error C2143: syntax error : missing ')' before ';'
Error executing cl.exe.
ValidaLogin.exe - 1 error(s), 1 warning(s)
-----------------
And if I use like this
char *s = http.GetPage(_T("http://192.168.0.16:8080/email/TmidiaServlet", true, "?user=Felipe?user=Felipe&pass=123"));
It works half way. I can access the server, but it receives NULL parameters... both 'user' and 'pass' , the server receives NULL.
Do you have any idea ???
Please, I need this SAP.
|
|
|
|
 |
|
 |
try this:
char *s = http.GetPage(_T("http://somewebpage/"), true, "?Username=SomeUser&Password=SomePassword&Otherdata=SomeMoreData");
you missed a ')'
bye
|
|
|
|
 |
|
 |
Hello,
I would like to send some data to a server (my login data) and get data out of the users area afterwards.
CAmHttpSocket http;
http.GetPage(_T("http://my.onvista.de/login.html"), true, "my login data");
http.GetPage(_T("http://my.onvista.de/login.html"));
char *s = http.GetPage(_T("http://my.onvista.de/mymarket/index.html"));
int i = http.GetPageStatusCode();
This didn't work. Does the class manage cookies?
If not, what can I do?
Thanks,
Michael
|
|
|
|
 |
|
 |
I tried using this code on a button press..
[code]
CAmHttpSocket http;
char *s = http.GetPage(_T("http://192.168.1.209/adeeltest/default.aspx[^]"),
true,
"?name=Adeel&Addy=Miami&Contact=343435454&mail=sanjeev@sampatti.com&address=florida&Comments=misc");
[/code]
but unfortunately its posting the data at all (I checked in the Database the table is blank). Can anyone please help me??
-- modified at 8:36 Monday 7th August, 2006
|
|
|
|
 |
|
 |
help me,i can't set proxy.
bool CAmHttpSocket::OpenUrl(const TCHAR *url)
{
if (hIS != NULL) InternetCloseHandle(hIS);
hIS = InternetOpenUrl(hIO, url, NULL, 0, HTTP_QUERY_DATE, 0);
if (hIS != NULL) return true;
else
{
LastError = GetLastError();
return false;
}
}
thank you
|
|
|
|
 |
|
 |
I enabled proxy server compatibility by changing line 69 of AmHttpSocket.cpp from:
hIO = InternetOpen(m_strAgentName, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
to
hIO = InternetOpen(m_strAgentName, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
works for me under Win XP SP2.
See: http://msdn.microsoft.com/en-us/library/aa383996(VS.85).aspx
|
|
|
|
 |
|
 |
Is it possible with this Class to post a XML File to the Server and recieve the answer?
If it is: how?
If not: does anybody know how to do it(Link to sample code)?
And another Problem:
unresolved external Symbol '__imp__InternetOpenA@20'
What library do I have to link to?
Thank you...
-- modified at 5:31 Thursday 6th April, 2006
|
|
|
|
 |
|
 |
in setting->General->object/Library modules: include
wininet.lib
and then try. it may work..
Viji
|
|
|
|
 |
|
 |
this class is'nt thread-safe.
If use more threads, must syncronize calls
|
|
|
|
 |
|
 |
Hey, i was testing your class to make some https requests but didn't work directly cause my server certificate isn't verified... GetLastError() is returning the 12045 error ( ERROR_INTERNET_INVALID_CA )
I found solution in msdn to handle that kind of problem:
article number 182888: http://support.microsoft.com/kb/q182888/
bool CAmHttpSocket::PostUrl(const TCHAR *url, const char *PostData, int PostDataLength)
{
//check length of postdata
if (PostDataLength == -1)
PostDataLength = strlen(PostData);
//some variable that we need...
URL_COMPONENTS uc;
//let's split the url...
uc.dwStructSize = sizeof(uc);
uc.lpszScheme = NULL;
uc.dwSchemeLength = 0;
uc.lpszHostName = NULL;
uc.dwHostNameLength = 1;
uc.nPort = 0;
uc.lpszUserName = NULL;
uc.dwUserNameLength = 0;
uc.lpszPassword = NULL;
uc.dwPasswordLength = 0;
uc.lpszUrlPath = NULL;
uc.dwUrlPathLength = 1;
uc.lpszExtraInfo = NULL;
uc.dwExtraInfoLength = 0;
InternetCrackUrl(url, _tcslen(url), 0, &uc);
//post the data...
if (hCO != NULL) InternetCloseHandle(hCO);
TCHAR *HostName = _tcsdup(uc.lpszHostName);
HostName[uc.dwHostNameLength] = '\0';
TCHAR *FileName = _tcsdup(uc.lpszUrlPath);
FileName[uc.dwUrlPathLength] = '\0';
if (hIS != NULL) InternetCloseHandle(hIS); //if open, close the handle to the connection
DWORD flags;
if (uc.nPort == 80)
{
//we are talking plain http
flags = INTERNET_FLAG_NO_CACHE_WRITE;
}
else
{
//we are talking secure https
flags = INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_SECURE |
INTERNET_FLAG_IGNORE_CERT_CN_INVALID | INTERNET_FLAG_IGNORE_CERT_DATE_INVALID ;
}
TCHAR headers[] = _T("Content-Type: application/x-www-form-urlencoded"); //content type for post...
TCHAR szAccept[] = _T("*/*"); //we accept everything...
LPTSTR AcceptTypes[2]={0};
AcceptTypes[0]=szAccept;
hCO = InternetConnect(hIO, HostName, uc.nPort, _T(""), _T(""), INTERNET_SERVICE_HTTP, INTERNET_FLAG_NO_CACHE_WRITE, 0);
hIS = HttpOpenRequest(hCO, _T("POST"), FileName, NULL, NULL, (LPCTSTR*)AcceptTypes, flags, 0);
again:
if (!HttpSendRequest(hIS, headers, _tcslen(headers), (TCHAR*)PostData, PostDataLength))
{
LastError = GetLastError();
if(LastError == ERROR_INTERNET_INVALID_CA)
{
DWORD dwFlags;
DWORD dwBuffLen = sizeof(dwFlags);
InternetQueryOption (hIS, INTERNET_OPTION_SECURITY_FLAGS,
(LPVOID)&dwFlags, &dwBuffLen);
dwFlags |= SECURITY_FLAG_IGNORE_UNKNOWN_CA;
InternetSetOption (hIS, INTERNET_OPTION_SECURITY_FLAGS,
&dwFlags, sizeof (dwFlags) );
goto again;
}
free(HostName);
free(FileName);
return false;
}
free(HostName);
free(FileName);
return true;
}
|
|
|
|
 |
|
 |
This may be a false alarm but visual studio indicates a memory leak in function
CAmHttpSocket::GetPage at this line ReceivedData = (char*)realloc(ReceivedData, curpos + rdsize);
|
|
|
|
 |
|
|
 |
|
 |
I included this files to my program and I have error like:
Linking...
AmHttpSocket.obj : error LNK2001: unresolved external symbol __imp__InternetOpenA@20
AmHttpSocket.obj : error LNK2001: unresolved external symbol __imp__InternetCloseHandle@4
AmHttpSocket.obj : error LNK2001: unresolved external symbol __imp__InternetOpenUrlA@24
AmHttpSocket.obj : error LNK2001: unresolved external symbol __imp__HttpSendRequestA@20
AmHttpSocket.obj : error LNK2001: unresolved external symbol __imp__HttpOpenRequestA@32
AmHttpSocket.obj : error LNK2001: unresolved external symbol __imp__InternetConnectA@32
AmHttpSocket.obj : error LNK2001: unresolved external symbol __imp__InternetCrackUrlA@16
AmHttpSocket.obj : error LNK2001: unresolved external symbol __imp__HttpQueryInfoA@20
AmHttpSocket.obj : error LNK2001: unresolved external symbol __imp__InternetReadFile@16
Debug/postdata.exe : fatal error LNK1120: 9 unresolved externals
Error executing link.exe.
What that error means?
How can I remove this error?
It will be fine if you help me
Sorry for my English Bye
|
|
|
|
 |
|
 |
[code]#pragma comment(lib, "wininet.lib")
#pragma once
#include
#include
#include [/code]
Should help (on MSVS)
|
|
|
|
 |
|
 |
D:\C\ALLEGRO\WWW/amhttpsocket.h(14) : error C2061: syntax error : identifier 'CAmHttpSocket'
D:\C\ALLEGRO\WWW/amhttpsocket.h(14) : error C2059: syntax error : ';'
D:\C\ALLEGRO\WWW/amhttpsocket.h(14) : error C2449: found '{' at file scope (missing function header?)
D:\C\ALLEGRO\WWW/amhttpsocket.h(29) : error C2059: syntax error : '}'
It looks like there is something wrong with the class ?
|
|
|
|
 |
|
 |
ahh sorry - my fault, wrong project linked ;|)
|
|
|
|
 |
|
 |
Using this functionality can I be able to transfer Unicode data
|
|
|
|
 |
|
 |
Just like to say thanks, found it very useful
|
|
|
|
 |
|
 |
worked straight out of the box for https, thanks very much.
|
|
|
|
 |
|
 |
hello
i want to get the web page and save it to the location i specify without viewing it how can it be done what functions will be used in this application.
du_aa
|
|
|
|
 |
|
 |
Hi...
Very Nice code u've written..Thanks..
But I don't find yet How to Upload file...
if u discover this..also...then Plz update this Class...
I'm waiting....
Thanks Again for such a nice code..
|
|
|
|
 |
|
 |
I am looking forward to uploading feature too...
Seems this class can only post a NULL terminated string, cannot post a buffer content.
Maybe someone experts can expand this class....
|
|
|
|
 |
|
 |
Nice to see reply after about 5 years...
At that time, even I fixed that issue. But now it's too long to even remember what exactly I did at that time.
Anyway, Thanks for reply(I can understand, how hard is to get free time. Even I hardly get).
Regards,
Sumit K.
sumit_kapoor1980@yahoo.com
Never consider anything impossible before trying to solve that..---Sumit Kapoor---
|
|
|
|
 |