Discussion:
HttpSendRequest isssues in handling authentication
(too old to reply)
kd_texas
2004-12-29 18:18:59 UTC
Permalink
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));
}
}
Brian Combs
2004-12-31 14:49:45 UTC
Permalink
Hello
I would use the debug build of WinInet to get a log file to see what is
happening. Also if you are not using port 80 for the request then your
network trace tool may just show TCP and not HTTP.

884931 How to use the debug version of the Wininet.dll file for Internet
http://support.microsoft.com/?id=884931

Thanks
Brian [MSFT]
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| From: "kd_texas" <***@newsgroup.nospam>
| Subject: HttpSendRequest isssues in handling authentication
| Date: Wed, 29 Dec 2004 12:18:59 -0600
| Lines: 123
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| X-RFC2646: Format=Flowed; Original
| Message-ID: <***@TK2MSFTNGP11.phx.gbl>
| Newsgroups: microsoft.public.inetsdk.programming.wininet
| NNTP-Posting-Host: cerberus.motive.com 216.110.85.132
| Path:
cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP0
8.phx.gbl!TK2MSFTNGP11.phx.gbl
| Xref: cpmsftngxa10.phx.gbl
microsoft.public.inetsdk.programming.wininet:11952
| X-Tomcat-NG: microsoft.public.inetsdk.programming.wininet
|
| 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,uint32PostDataByt
es))
| {
| 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));
| }
| }
|
|
|

Loading...