kd_texas
2004-12-29 18:18:59 UTC
Guys,
I have one client application which is talking to a UPnP device. this device
is connected locally to my machine on ip address 192.168.1.1, and works as a
http server.
Server supports digest authentication. I am sending http request with right
credential to this device, but HttpSendRequest fail with last error 12015
(login failure).
Here is how it it should work in case of digest authentication-
1.-Client sends http request to Server
2.-Sever responds back with 401 and with digest header information.
3.-Client re-sends request with digest authentication header. - (Note: I
don't see this request with my code)
4. Server accepts credential & responds back with data
As far as I know, HttpSendRequest should automatically take care of
authentication process (step 1-3) if user crendentials are specified when
calling InternetConnect.but this is not happening in my case.
I can see step-2 (server responding with 401), but client never send second
request with digest information.
I have seen it working with other some http server with digest
authentication on my intranet, but looks like same code fails when I talk to
this local device supporting http server.
It looks to me something is different when talking to local server (setup on
192.168.1.1). I looked at the packet tarce, and I can see there is some
protocol diference. In case of my other server on intranet, protocol is
reported as "HTTP", while talking to device protocol is reported as TCP.
Will this make any difference in WinInet behaviour? If yes, how to fix it?
Here is the code logic
HINTERNET hInternetConnect = m_pThreadData->GetInternetConnectHandle();
if (NULL == hInternetConnect){
hInternetConnect = m_pWinInet->InternetConnect(hInternetOpen,
strServer, vInternetPort, lpszUserName,lpszPassword,INTERNET_SERVICE_HTTP,0,
::GetCurrentThreadId());
if (NULL == hInternetConnect){
if (m_pThreadData->IsAborted())
{
WALOG_DEBUG(WINHTTPLOG_WIHTTP,
IDS_WIHTTP_INETREADFILEABORTED);
throw ConnectThreadException(HttpStatus::AbortFailure);
}
else
{
DWORD dwError = ::GetLastError();
WALOG_ERROR1(WINHTTPLOG_WIHTTP, IDS_WIHTTP_INETCONNECTFAIL,
dwError);
throw ConnectThreadException(WinInetErrorTranslate(dwError,
HttpStatus::InetSubsystemConnectFailure));
}
}
m_pThreadData->SetInternetConnectHandle(hInternetConnect);
}
m_pThreadData->UpdateLastActivityTime();
// JDR - we need to re-assess the HTTP flags we want and don't want
//
DWORD dwHttpRequestFlags = INTERNET_FLAG_RELOAD;
if (fKeepConnectionOpen)
{
dwHttpRequestFlags |= INTERNET_FLAG_KEEP_CONNECTION;
}
if (vInternetScheme == INTERNET_SCHEME_HTTPS)
{
dwHttpRequestFlags |= INTERNET_FLAG_SECURE;
dwHttpRequestFlags |= INTERNET_FLAG_IGNORE_CERT_DATE_INVALID;
dwHttpRequestFlags |= INTERNET_FLAG_IGNORE_CERT_CN_INVALID;
}
char* pszPostData = NULL;
UINT32 uint32PostDataBytes = 0;
bool fHttpPostOp = m_pThreadData->GetPostData(pszPostData,
uint32PostDataBytes);
CStringA strHttpVerb = HTTP_VERB_GET;
if (fHttpPostOp)
{
strHttpVerb = HTTP_VERB_POST;
}
hHttpOpen =
m_pWinInet->HttpOpenRequest(hInternetConnect,strHttpVerb,strUrlPath,
HTTP_VERSION,NULL,NULL,dwHttpRequestFlags,::GetCurrentThreadId());
if (NULL == hHttpOpen)
{
if (m_pThreadData->IsAborted())
{
WALOG_DEBUG(WINHTTPLOG_WIHTTP, IDS_WIHTTP_INETREADFILEABORTED);
throw ConnectThreadException(HttpStatus::AbortFailure);
}
else
{
DWORD dwError = ::GetLastError();
WALOG_ERROR1(WINHTTPLOG_WIHTTP, IDS_WIHTTP_HTTPOPENREQUESTFAIL,
dwError);
throw ConnectThreadException(WinInetErrorTranslate(dwError,
HttpStatus::InetSubsystemHttpOpenFailure));
}
}
m_pThreadData->UpdateLastActivityTime();
if (!pHttpClient->ProcessRequestHeaders(hHttpOpen))
{
throw
ConnectThreadException(HttpStatus::InetSubsystemInvalidRequestHeaders);
}
if
(!m_pWinInet->HttpSendRequest(hHttpOpen,NULL,0,pszPostData,uint32PostDataBytes))
{
if (m_pThreadData->IsAborted())
{
WALOG_DEBUG(WINHTTPLOG_WIHTTP, IDS_WIHTTP_INETREADFILEABORTED);
throw ConnectThreadException(HttpStatus::AbortFailure);
}
else
{
DWORD dwError = ::GetLastError();
WALOG_ERROR1(WINHTTPLOG_WIHTTP, IDS_WIHTTP_HTTPSENDREQUESTFAIL,
dwError);
throw ConnectThreadException(WinInetErrorTranslate(dwError,
HttpStatus::InetSubsystemHttpSendFailure));
}
}
I have one client application which is talking to a UPnP device. this device
is connected locally to my machine on ip address 192.168.1.1, and works as a
http server.
Server supports digest authentication. I am sending http request with right
credential to this device, but HttpSendRequest fail with last error 12015
(login failure).
Here is how it it should work in case of digest authentication-
1.-Client sends http request to Server
2.-Sever responds back with 401 and with digest header information.
3.-Client re-sends request with digest authentication header. - (Note: I
don't see this request with my code)
4. Server accepts credential & responds back with data
As far as I know, HttpSendRequest should automatically take care of
authentication process (step 1-3) if user crendentials are specified when
calling InternetConnect.but this is not happening in my case.
I can see step-2 (server responding with 401), but client never send second
request with digest information.
I have seen it working with other some http server with digest
authentication on my intranet, but looks like same code fails when I talk to
this local device supporting http server.
It looks to me something is different when talking to local server (setup on
192.168.1.1). I looked at the packet tarce, and I can see there is some
protocol diference. In case of my other server on intranet, protocol is
reported as "HTTP", while talking to device protocol is reported as TCP.
Will this make any difference in WinInet behaviour? If yes, how to fix it?
Here is the code logic
HINTERNET hInternetConnect = m_pThreadData->GetInternetConnectHandle();
if (NULL == hInternetConnect){
hInternetConnect = m_pWinInet->InternetConnect(hInternetOpen,
strServer, vInternetPort, lpszUserName,lpszPassword,INTERNET_SERVICE_HTTP,0,
::GetCurrentThreadId());
if (NULL == hInternetConnect){
if (m_pThreadData->IsAborted())
{
WALOG_DEBUG(WINHTTPLOG_WIHTTP,
IDS_WIHTTP_INETREADFILEABORTED);
throw ConnectThreadException(HttpStatus::AbortFailure);
}
else
{
DWORD dwError = ::GetLastError();
WALOG_ERROR1(WINHTTPLOG_WIHTTP, IDS_WIHTTP_INETCONNECTFAIL,
dwError);
throw ConnectThreadException(WinInetErrorTranslate(dwError,
HttpStatus::InetSubsystemConnectFailure));
}
}
m_pThreadData->SetInternetConnectHandle(hInternetConnect);
}
m_pThreadData->UpdateLastActivityTime();
// JDR - we need to re-assess the HTTP flags we want and don't want
//
DWORD dwHttpRequestFlags = INTERNET_FLAG_RELOAD;
if (fKeepConnectionOpen)
{
dwHttpRequestFlags |= INTERNET_FLAG_KEEP_CONNECTION;
}
if (vInternetScheme == INTERNET_SCHEME_HTTPS)
{
dwHttpRequestFlags |= INTERNET_FLAG_SECURE;
dwHttpRequestFlags |= INTERNET_FLAG_IGNORE_CERT_DATE_INVALID;
dwHttpRequestFlags |= INTERNET_FLAG_IGNORE_CERT_CN_INVALID;
}
char* pszPostData = NULL;
UINT32 uint32PostDataBytes = 0;
bool fHttpPostOp = m_pThreadData->GetPostData(pszPostData,
uint32PostDataBytes);
CStringA strHttpVerb = HTTP_VERB_GET;
if (fHttpPostOp)
{
strHttpVerb = HTTP_VERB_POST;
}
hHttpOpen =
m_pWinInet->HttpOpenRequest(hInternetConnect,strHttpVerb,strUrlPath,
HTTP_VERSION,NULL,NULL,dwHttpRequestFlags,::GetCurrentThreadId());
if (NULL == hHttpOpen)
{
if (m_pThreadData->IsAborted())
{
WALOG_DEBUG(WINHTTPLOG_WIHTTP, IDS_WIHTTP_INETREADFILEABORTED);
throw ConnectThreadException(HttpStatus::AbortFailure);
}
else
{
DWORD dwError = ::GetLastError();
WALOG_ERROR1(WINHTTPLOG_WIHTTP, IDS_WIHTTP_HTTPOPENREQUESTFAIL,
dwError);
throw ConnectThreadException(WinInetErrorTranslate(dwError,
HttpStatus::InetSubsystemHttpOpenFailure));
}
}
m_pThreadData->UpdateLastActivityTime();
if (!pHttpClient->ProcessRequestHeaders(hHttpOpen))
{
throw
ConnectThreadException(HttpStatus::InetSubsystemInvalidRequestHeaders);
}
if
(!m_pWinInet->HttpSendRequest(hHttpOpen,NULL,0,pszPostData,uint32PostDataBytes))
{
if (m_pThreadData->IsAborted())
{
WALOG_DEBUG(WINHTTPLOG_WIHTTP, IDS_WIHTTP_INETREADFILEABORTED);
throw ConnectThreadException(HttpStatus::AbortFailure);
}
else
{
DWORD dwError = ::GetLastError();
WALOG_ERROR1(WINHTTPLOG_WIHTTP, IDS_WIHTTP_HTTPSENDREQUESTFAIL,
dwError);
throw ConnectThreadException(WinInetErrorTranslate(dwError,
HttpStatus::InetSubsystemHttpSendFailure));
}
}