Hi experts I need to send an http request from C++ application using wininet API. User is behind ISA proxy server that is configured to use Integrated Windows Authentication. When I get error 407 (proxy authentication required) I use InternetErrorDlg to ask the user for credentials. This is not an ideal solution as the IE is able to use current user's credentials transparently. Is there a way to do this?
Sample code for request
hRequest = HttpOpenRequest (
hConnect,
"POST",
query.c_str(),
HTTP_VERSION,
NULL,
cAcceptTypes,
INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE| INTERNET_FLAG_KEEP_CONNECTION,
0);
bRet = HttpSendRequest(
hRequest,
NULL,
0,
(LPVOID)dataXml.c_str(),
(DWORD)dataXml.length());
bRet = HttpQueryInfo(
hRequest,
HTTP_QUERY_FLAG_NUMBER | HTTP_QUERY_STATUS_CODE,
&dwStatus,
&dwSize,
NULL);
if (dwStatus == HTTP_STATUS_PROXY_AUTH_REQ)
{
ProxyAuthenticate( hRequest ); // Here I call InternetErrorDlg
bRet = HttpSendRequest(
hRequest,
NULL,
0,
(LPVOID)dataXml.c_str(),
(DWORD)dataXml.length());
}
Try to use INTERNET_OPEN_TYPE_PRECONFIG
to initialize Wininet in your process:
InternetOpen(clientName, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.