thanks stephen for ur valuble reply
actually my entire code is as follows
using System;
using WinHttp;
namespace PacProxyUsage
{
public class Proxy
{
public Proxy()
{
}
unsafe public static string GetProxyForUrlUsingPac ( string
DestinationUrl, string PacUri ){
WinHttpRequest req=new WinHttpRequest();
IntPtr WinHttpSession = Win32Api.WinHttpOpen("User",
Win32Api.WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, null, IntPtr.Zero, 0);
char [] buf=new char[100];
Win32Api.WINHTTP_AUTOPROXY_OPTIONS ProxyOptions = new
Win32Api.WINHTTP_AUTOPROXY_OPTIONS();
Win32Api.WINHTTP_PROXY_INFO ProxyInfo = new
Win32Api.WINHTTP_PROXY_INFO();
Win32Api.WINHTTP_CERTIFICATE_INFO certificate= new
Win32Api.WINHTTP_CERTIFICATE_INFO();
ProxyOptions.dwFlags =
Win32Api.WINHTTP_AUTOPROXY_CONFIG_URL;
ProxyOptions.dwAutoDetectFlags =
(Win32Api.WINHTTP_AUTO_DETECT_TYPE_DHCP |
Win32Api.WINHTTP_AUTO_DETECT_TYPE_DNS_A);
ProxyOptions.lpszAutoConfigUrl = PacUri;
bool IsSuccess = Win32Api.WinHttpGetProxyForUrl(
WinHttpSession, DestinationUrl, ref ProxyOptions, ref ProxyInfo );
string url;
bool
flag=Win32Api.WinHttpDetectAutoProxyConfigUrl(Win32Api.WINHTTP_AUTO_DETECT_TYPE_DHCP,out
url);
Console.WriteLine(url);
IntPtr WinHttpSession1 = Win32Api.WinHttpOpen("User",
Win32Api.WINHTTP_ACCESS_TYPE_NAMED_PROXY, ProxyInfo.lpszProxy,
IntPtr.Zero, 0);
IntPtr
Winconnection=Win32Api.WinHttpConnect(WinHttpSession,"www.mygdc.com",0,0);
IntPtr
id=Win32Api.WinHttpOpenRequest(Winconnection,"POST","/winn/01Primary/",null,null,null,0x00800000);
int dwword = Win32Api.SECURITY_FLAG_IGNORE_CERT_CN_INVALID |
Win32Api.SECURITY_FLAG_IGNORE_CERT_DATE_INVALID |
Win32Api.SECURITY_FLAG_IGNORE_UNKNOWN_CA;
int
size=System.Runtime.InteropServices.Marshal.SizeOf(dwword);
Win32Api.WinHttpSetOption(id,31, &dwword,size);
Console.WriteLine("Error: {0}", Win32Api.GetLastError() );
bool result1=Win32Api.WinHttpSendRequest(id,null,0,null,0,0,0);
bool res=
Win32Api.WinHttpSetCredentials(id,Win32Api.WINHTTP_AUTH_TARGET_SERVER,Win32Api.WINHTTP_AUTH_SCHEME_BASIC,"test","test",null);
bool re=Win32Api.WinHttpReceiveResponse(id,null);
WinHttpQueryOption(id,WINHTTP_OPTION_SERVER_CERT_CONTEXT , ref
certificate,sizeof(certificate));
Console.WriteLine("Error: {0}", Win32Api.GetLastError() );
Win32Api.WinHttpCloseHandle(WinHttpSession1);
Win32Api.WinHttpCloseHandle(Winconnection);
if (IsSuccess){
return ProxyInfo.lpszProxy;
}else {
Console.WriteLine("Error: {0}", Win32Api.GetLastError()
);
return null;
}
}
}
}
but my winhttpqueryoption function returning invalid parameters.
please help me to solve this problem for retriving the server's
certificate.
regards
bharathi
Post by Stephen Sulzerbharathi,
You need to send a request to the server before you can query for the
server's certificate information. Then use the request handle in the call to
WinHttpQueryOption. The SERVER_CERT_CONTEXT option can only be queried on a
request handle. WinHttp does not actually establish any connection with a
server until the call to WinHttpSendRequest. You should be able to query the
server's certificate right after WinHttpSendRequest and before any calls to
WinHttpWriteData/WinHttpReceiveResponse.
Regards,
- Stephen