Discussion:
Newbie in Internet Programming
(too old to reply)
Girish
2006-03-08 10:34:19 UTC
Permalink
Hello Friends,

I am very new to this forums , I am trying to connect
to a proxy using this code but i am getting error when i am using the
function HttpOpenRequest() i am getting the Error Code 122. Can anybody solve
my problem Following is the Code

AfxParseURL(m_URL,dwAccessType,m_Server,m_sObject,m_port);


m_hInternetSession=InternetOpen(AfxGetAppName(),dwAccessType,m_Server,NULL,INTERNET_OPEN_TYPE_PROXY)
if(::InternetSetStatusCallback(m_hInternetSession,_OnStatusCallBack)==INTERNET_INVALID_STATUS_CALLBACK)
{
AfxMessageBox("Invalid Status Callback");
}
m_hHttpConnection=InternetConnect(m_hInternetSession,m_Server,m_port,NULL,
NULL,INTERNET_SERVICE_HTTP,0,(DWORD)this);
retErr=GetLastError();

if (dwAccessType == AFX_INET_SERVICE_HTTPS)
dwFlags |= (INTERNET_FLAG_SECURE | INTERNET_FLAG_IGNORE_CERT_CN_INVALID |
INTERNET_FLAG_IGNORE_CERT_DATE_INVALID);


m_hHttpFile = ::HttpOpenRequest(m_hHttpConnection, NULL,

(m_sObject.GetBuffer(m_sObject.GetLength())),

_T("HTTP/1.1"), NULL, ppszAcceptTypes,

dwFlags,(DWORD)this);
retErr=GetLastError();


Thanks in Advance
Girish
Scherbina Vladimir
2006-03-08 17:59:10 UTC
Permalink
Hello, Girish.

What is the return value of HttpOpenRequest ? Is it NULL ? 122 is the error
code that you get via GetLastError after HttpOpenRequest returned NULL?
--
Vladimir
http://spaces.msn.com/vladimir-scherbina/
Post by Girish
Hello Friends,
I am very new to this forums , I am trying to connect
to a proxy using this code but i am getting error when i am using the
function HttpOpenRequest() i am getting the Error Code 122. Can anybody solve
my problem Following is the Code
AfxParseURL(m_URL,dwAccessType,m_Server,m_sObject,m_port);
m_hInternetSession=InternetOpen(AfxGetAppName(),dwAccessType,m_Server,NULL,INTERNET_OPEN_TYPE_PROXY);
if(::InternetSetStatusCallback(m_hInternetSession,_OnStatusCallBack)==INTERNET_INVALID_STATUS_CALLBACK)
{
AfxMessageBox("Invalid Status Callback");
}
m_hHttpConnection=InternetConnect(m_hInternetSession,m_Server,m_port,NULL,
NULL,INTERNET_SERVICE_HTTP,0,(DWORD)this);
retErr=GetLastError();
if (dwAccessType == AFX_INET_SERVICE_HTTPS)
dwFlags |= (INTERNET_FLAG_SECURE | INTERNET_FLAG_IGNORE_CERT_CN_INVALID |
INTERNET_FLAG_IGNORE_CERT_DATE_INVALID);
m_hHttpFile = ::HttpOpenRequest(m_hHttpConnection, NULL,
(m_sObject.GetBuffer(m_sObject.GetLength())),
_T("HTTP/1.1"), NULL, ppszAcceptTypes,
dwFlags,(DWORD)this);
retErr=GetLastError();
Thanks in Advance
Girish
Girish
2006-03-09 06:53:28 UTC
Permalink
Hi Scherbina Vladimir
Hope i have spelled ur name correctly, Correct me if i m wrong


Yeah ur reply is right , i am getting the Error Code 122
So Exactly where i am wrong, Why mine HttpOpenRequest() is failing



With Rgds
Girish
Scherbina Vladimir
2006-03-09 08:49:44 UTC
Permalink
What happens if you're connecting not via proxy server ? Can you track using
sniffer (Iris for example) what reply you get from proxy ?
--
Vladimir
http://spaces.msn.com/vladimir-scherbina/
Post by Girish
Hi Scherbina Vladimir
Hope i have spelled ur name correctly, Correct me if i m wrong
Yeah ur reply is right , i am getting the Error Code 122
So Exactly where i am wrong, Why mine HttpOpenRequest() is failing
With Rgds
Girish
Girish
2006-03-10 11:29:29 UTC
Permalink
Hi Scherbina Vladimir,

As u told i have verified the packets using Sniffer software, it
shows be the Server Name as Microsot IIS instead of the Actual Site.

I am behind a proxy, and if i am sending without username and
password it shows me Error Code "407" Authorization

But if i provide username and password it shows me success with code
"200"

I am not encrypting the username and password is this the reason of
the Error ?


Pls guide me further

With Rgds
Girish
Scherbina Vladimir
2006-03-11 00:28:07 UTC
Permalink
Girish,

Can you publish here all your code ? It's better to attach it to a letter
(in case if you're using Outlook Express).
--
Vladimir
http://spaces.msn.com/vladimir-scherbina/
Post by Girish
Hi Scherbina Vladimir,
As u told i have verified the packets using Sniffer software, it
shows be the Server Name as Microsot IIS instead of the Actual Site.
I am behind a proxy, and if i am sending without username and
password it shows me Error Code "407" Authorization
But if i provide username and password it shows me success with code
"200"
I am not encrypting the username and password is this the reason of
the Error ?
Pls guide me further
With Rgds
Girish
Girish
2006-03-11 13:41:30 UTC
Permalink
CInternetSession *pSession = new CInternetSession(_T("GetIPNr"), 1,

INTERNET_OPEN_TYPE_PROXY,
"192.168.0.10",NULL,0);

CHttpConnection* pConnection =

pSession->GetHttpConnection(_T("checkip.dyndns.org"),
1,808,NULL,NULL);

CHttpFile* pFile = pConnection->OpenRequest(CHttpConnection::HTTP_VERB_GET,
_T("/"));

CString szAuthLine="girish:girish2005"; //proxy username and password

pFile->AddRequestHeaders(szAuthLine, HTTP_ADDREQ_FLAG_ADD,
strlen(szAuthLine));

BOOL bResult;
DWORD dwRet;
bResult = pFile->SendRequest();

pFile->QueryInfoStatusCode(dwRet); //show 200 =Success

if(dwRet== 200)
{
char *p = new char[1024];
pFile->Read(p, 1024); // Now read first 1024 bytes of HTML.
}

But when i read the contents it is not what is expected


I used Ether Detect packet sniffer to check the packets and it showed me

Microsoft IIS server in place of server name, Expected was the url of the
website


Pls guide me
Girish
2006-03-13 09:59:27 UTC
Permalink
Hi Scherbina Vladimir
Thanks very much for persisting with me.
Atlast my problem is been solved, thanks very much without it
wouldn't have
been possible.

One more thing when i use INTERNET_OPEN_TYPE_PRECONFIG as the
parameter
in Class CInternetSession it works, but it fails when i use
INTERNET_OPEN_TYPE_PROXY parameter, can u Explain that ?

With Rgds
Girish
Scherbina Vladimir
2006-03-13 17:33:05 UTC
Permalink
Girish, glad to hear that all seems to work.

When you use INTERNET_OPEN_TYPE_PRECONFIG param wininet uses settings and
credentials configured by you(or probably by administrator) in order to make
connection to resource located at global network. As you told us you're
behind the proxy, so INTERNET_OPEN_TYPE_PRECONFIG get proxy username,
password address and establishes connection to proxy with this info.

In case when you use INTERNET_OPEN_TYPE_PROXY param you *manually* connect
to proxy and thus need to send password and username values in headers.
--
Vladimir
http://spaces.msn.com/vladimir-scherbina/
Hans
2006-03-10 18:37:29 UTC
Permalink
Try this:

GlobalProxySelection.Select = new WebProxy("127.0.0.1", 8888);
Post by Girish
Hello Friends,
I am very new to this forums , I am trying to connect
to a proxy using this code but i am getting error when i am using the
function HttpOpenRequest() i am getting the Error Code 122. Can anybody solve
my problem Following is the Code
AfxParseURL(m_URL,dwAccessType,m_Server,m_sObject,m_port);
m_hInternetSession=InternetOpen(AfxGetAppName(),dwAccessType,m_Server,NULL,INTERNET_OPEN_TYPE_PROXY);
if(::InternetSetStatusCallback(m_hInternetSession,_OnStatusCallBack)==INTERNET_INVALID_STATUS_CALLBACK)
{
AfxMessageBox("Invalid Status Callback");
}
m_hHttpConnection=InternetConnect(m_hInternetSession,m_Server,m_port,NULL,
NULL,INTERNET_SERVICE_HTTP,0,(DWORD)this);
retErr=GetLastError();
if (dwAccessType == AFX_INET_SERVICE_HTTPS)
dwFlags |= (INTERNET_FLAG_SECURE | INTERNET_FLAG_IGNORE_CERT_CN_INVALID |
INTERNET_FLAG_IGNORE_CERT_DATE_INVALID);
m_hHttpFile = ::HttpOpenRequest(m_hHttpConnection, NULL,
(m_sObject.GetBuffer(m_sObject.GetLength())),
_T("HTTP/1.1"), NULL, ppszAcceptTypes,
dwFlags,(DWORD)this);
retErr=GetLastError();
Thanks in Advance
Girish
Loading...