本文整理汇总了C#中Interop.WinHttp.SafeWinHttpHandle类的典型用法代码示例。如果您正苦于以下问题:C# Interop.WinHttp.SafeWinHttpHandle类的具体用法?C# Interop.WinHttp.SafeWinHttpHandle怎么用?C# Interop.WinHttp.SafeWinHttpHandle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Interop.WinHttp.SafeWinHttpHandle类属于命名空间,在下文中一共展示了Interop.WinHttp.SafeWinHttpHandle类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: WinHttpRequestStream
internal WinHttpRequestStream(SafeWinHttpHandle requestHandle, bool chunkedMode)
{
bool ignore = false;
requestHandle.DangerousAddRef(ref ignore);
_requestHandle = requestHandle;
_chunkedMode = chunkedMode;
}
开发者ID:jmhardison,项目名称:corefx,代码行数:7,代码来源:WinHttpRequestStream.cs
示例2: WinHttpConnect
public static SafeWinHttpHandle WinHttpConnect(
SafeWinHttpHandle sessionHandle,
string serverName,
ushort serverPort,
uint reserved)
{
return new FakeSafeWinHttpHandle(true);
}
开发者ID:peterblazejewicz,项目名称:corefx,代码行数:8,代码来源:FakeInterop.cs
示例3: SetChannelBinding
internal void SetChannelBinding(SafeWinHttpHandle requestHandle)
{
var channelBinding = new WinHttpChannelBinding(requestHandle);
if (channelBinding.IsInvalid)
{
channelBinding.Dispose();
}
else
{
_channelBinding = channelBinding;
}
}
开发者ID:noahfalk,项目名称:corefx,代码行数:13,代码来源:WinHttpTransportContext.cs
示例4: WinHttpResponseStream
internal WinHttpResponseStream(
SafeWinHttpHandle sessionHandle,
SafeWinHttpHandle connectHandle,
SafeWinHttpHandle requestHandle)
{
// While we only use the requestHandle to do actual reads of the response body,
// we need to keep the parent handles (connection, session) alive as well.
bool ignore = false;
sessionHandle.DangerousAddRef(ref ignore);
connectHandle.DangerousAddRef(ref ignore);
requestHandle.DangerousAddRef(ref ignore);
_sessionHandle = sessionHandle;
_connectHandle = connectHandle;
_requestHandle = requestHandle;
}
开发者ID:peterblazejewicz,项目名称:corefx,代码行数:15,代码来源:WinHttpResponseStream.cs
示例5: WinHttpChannelBinding
internal WinHttpChannelBinding(SafeWinHttpHandle requestHandle)
{
IntPtr data = IntPtr.Zero;
uint dataSize = 0;
if (!Interop.WinHttp.WinHttpQueryOption(requestHandle, Interop.WinHttp.WINHTTP_OPTION_SERVER_CBT, null, ref dataSize))
{
if (Marshal.GetLastWin32Error() == Interop.WinHttp.ERROR_INSUFFICIENT_BUFFER)
{
data = Marshal.AllocHGlobal((int)dataSize);
if (Interop.WinHttp.WinHttpQueryOption(requestHandle, Interop.WinHttp.WINHTTP_OPTION_SERVER_CBT, data, ref dataSize))
{
SetHandle(data);
_size = (int)dataSize;
}
else
{
Marshal.FreeHGlobal(data);
}
}
}
}
开发者ID:ChuangYang,项目名称:corefx,代码行数:23,代码来源:WinHttpChannelBinding.cs
示例6: SetNoClientCertificate
private static void SetNoClientCertificate(SafeWinHttpHandle requestHandle)
{
SetWinHttpOption(
requestHandle,
Interop.WinHttp.WINHTTP_OPTION_CLIENT_CERT_CONTEXT,
IntPtr.Zero,
0);
}
开发者ID:JerryForNet,项目名称:corefx,代码行数:8,代码来源:WinHttpHandler.cs
示例7: SetRequestHandleClientCertificateOptions
private void SetRequestHandleClientCertificateOptions(SafeWinHttpHandle requestHandle, Uri requestUri)
{
// Must be HTTPS scheme to use client certificates.
if (requestUri.Scheme != UriSchemeHttps)
{
return;
}
// Get candidate list for client certificates.
X509Certificate2Collection certs;
if (_clientCertificateOption == ClientCertificateOption.Manual)
{
certs = ClientCertificates;
}
else
{
using (var myStore = new X509Store())
{
myStore.Open(OpenFlags.OpenExistingOnly | OpenFlags.ReadOnly);
certs = myStore.Certificates;
}
}
// Check for no certs now as a performance optimization.
if (certs.Count == 0)
{
SetNoClientCertificate(requestHandle);
return;
}
// Reduce the set of certificates to match the proper 'Client Authentication' criteria.
certs = certs.Find(X509FindType.FindByKeyUsage, X509KeyUsageFlags.DigitalSignature, true);
certs = certs.Find(X509FindType.FindByApplicationPolicy, ClientAuthenticationOID, true);
// Build a new collection with certs that have a private key. Need to do this
// manually because there is no X509FindType to match this criteria.
var clientCerts = new X509Certificate2Collection();
foreach (var cert in certs)
{
if (cert.HasPrivateKey)
{
clientCerts.Add(cert);
}
}
// TOOD: Filter the list based on TrustedIssuerList info from WINHTTP.
// Set the client certificate.
if (certs.Count == 0)
{
SetNoClientCertificate(requestHandle);
}
else
{
SetWinHttpOption(
requestHandle,
Interop.WinHttp.WINHTTP_OPTION_CLIENT_CERT_CONTEXT,
clientCerts[0].Handle,
(uint)Marshal.SizeOf<Interop.Crypt32.CERT_CONTEXT>());
}
}
开发者ID:JerryForNet,项目名称:corefx,代码行数:61,代码来源:WinHttpHandler.cs
示例8: AddRequestHeaders
private static void AddRequestHeaders(
SafeWinHttpHandle requestHandle,
HttpRequestMessage requestMessage,
CookieContainer cookies)
{
var requestHeadersBuffer = new StringBuilder();
// Manually add cookies.
if (cookies != null)
{
string cookieHeader = GetCookieHeader(requestMessage.RequestUri, cookies);
if (!string.IsNullOrEmpty(cookieHeader))
{
requestHeadersBuffer.AppendLine(cookieHeader);
}
}
// Serialize general request headers.
requestHeadersBuffer.AppendLine(requestMessage.Headers.ToString());
// Serialize entity-body (content) headers.
if (requestMessage.Content != null)
{
// TODO: Content-Length header isn't getting correctly placed using ToString()
// This is a bug in HttpContentHeaders that needs to be fixed.
if (requestMessage.Content.Headers.ContentLength.HasValue)
{
long contentLength = requestMessage.Content.Headers.ContentLength.Value;
requestMessage.Content.Headers.ContentLength = null;
requestMessage.Content.Headers.ContentLength = contentLength;
}
requestHeadersBuffer.AppendLine(requestMessage.Content.Headers.ToString());
}
// Add request headers to WinHTTP request handle.
if (!Interop.WinHttp.WinHttpAddRequestHeaders(
requestHandle,
requestHeadersBuffer,
(uint)requestHeadersBuffer.Length,
Interop.WinHttp.WINHTTP_ADDREQ_FLAG_ADD))
{
WinHttpException.ThrowExceptionUsingLastError();
}
}
开发者ID:JerryForNet,项目名称:corefx,代码行数:45,代码来源:WinHttpHandler.cs
示例9: ParseResponseHeaders
private void ParseResponseHeaders(
SafeWinHttpHandle requestHandle,
HttpResponseMessage response,
bool stripEncodingHeaders)
{
string rawResponseHeaders = GetResponseHeaderStringInfo(
requestHandle,
Interop.WinHttp.WINHTTP_QUERY_RAW_HEADERS_CRLF);
string[] responseHeaderArray = rawResponseHeaders.Split(
s_httpHeadersSeparator,
StringSplitOptions.RemoveEmptyEntries);
// Parse the array of headers and split them between Content headers and Response headers.
// Skip the first line which contains status code, etc. information that we already parsed.
for (int i = 1; i < responseHeaderArray.Length; i++)
{
int colonIndex = responseHeaderArray[i].IndexOf(':');
// Skip malformed header lines that are missing the colon character.
if (colonIndex > 0)
{
string headerName = responseHeaderArray[i].Substring(0, colonIndex);
string headerValue = responseHeaderArray[i].Substring(colonIndex + 1).Trim(); // Normalize header value by trimming white space.
if (!response.Headers.TryAddWithoutValidation(headerName, headerValue))
{
if (stripEncodingHeaders)
{
// Remove Content-Length and Content-Encoding headers if we are
// decompressing the response stream in the handler (due to
// WINHTTP not supporting it in a particular downlevel platform).
// This matches the behavior of WINHTTP when it does decompression iself.
if (string.Equals(
HeaderNameContentLength,
headerName,
StringComparison.OrdinalIgnoreCase))
{
continue;
}
if (string.Equals(
HeaderNameContentEncoding,
headerName,
StringComparison.OrdinalIgnoreCase))
{
continue;
}
}
// TODO: Should we log if there is an error here?
response.Content.Headers.TryAddWithoutValidation(headerName, headerValue);
}
}
}
}
开发者ID:JerryForNet,项目名称:corefx,代码行数:55,代码来源:WinHttpHandler.cs
示例10: GetResponseHeaderNumberInfo
private uint GetResponseHeaderNumberInfo(SafeWinHttpHandle requestHandle, uint infoLevel)
{
uint result = 0;
uint resultSize = sizeof(uint);
if (!Interop.WinHttp.WinHttpQueryHeaders(
requestHandle,
infoLevel | Interop.WinHttp.WINHTTP_QUERY_FLAG_NUMBER,
Interop.WinHttp.WINHTTP_HEADER_NAME_BY_INDEX,
ref result,
ref resultSize,
IntPtr.Zero))
{
WinHttpException.ThrowExceptionUsingLastError();
}
return result;
}
开发者ID:JerryForNet,项目名称:corefx,代码行数:18,代码来源:WinHttpHandler.cs
示例11: SetWinHttpOption
private static void SetWinHttpOption(
SafeWinHttpHandle handle,
uint option,
IntPtr optionData,
uint optionSize)
{
if (!Interop.WinHttp.WinHttpSetOption(
handle,
option,
optionData,
optionSize))
{
WinHttpException.ThrowExceptionUsingLastError();
}
}
开发者ID:JerryForNet,项目名称:corefx,代码行数:15,代码来源:WinHttpHandler.cs
示例12: SetRequestHandleBufferingOptions
private void SetRequestHandleBufferingOptions(SafeWinHttpHandle requestHandle)
{
uint optionData = (uint)_maxResponseHeadersLength;
SetWinHttpOption(requestHandle, Interop.WinHttp.WINHTTP_OPTION_MAX_RESPONSE_HEADER_SIZE, ref optionData);
optionData = (uint)_maxResponseDrainSize;
SetWinHttpOption(requestHandle, Interop.WinHttp.WINHTTP_OPTION_MAX_RESPONSE_DRAIN_SIZE, ref optionData);
}
开发者ID:JerryForNet,项目名称:corefx,代码行数:7,代码来源:WinHttpHandler.cs
示例13: WinHttpAddRequestHeaders
public static bool WinHttpAddRequestHeaders(
SafeWinHttpHandle requestHandle,
StringBuilder headers,
uint headersLength,
uint modifiers)
{
return true;
}
开发者ID:nnyamhon,项目名称:corefx,代码行数:8,代码来源:FakeInterop.cs
示例14: WinHttpSetStatusCallback
public static IntPtr WinHttpSetStatusCallback(
SafeWinHttpHandle handle,
Interop.WinHttp.WINHTTP_STATUS_CALLBACK callback,
uint notificationFlags,
IntPtr reserved)
{
if (handle == null)
{
throw new ArgumentNullException("handle");
}
return IntPtr.Zero;
}
开发者ID:nnyamhon,项目名称:corefx,代码行数:13,代码来源:FakeInterop.cs
示例15: WinHttpGetProxyForUrl
public static bool WinHttpGetProxyForUrl(
SafeWinHttpHandle sessionHandle,
string url,
ref Interop.WinHttp.WINHTTP_AUTOPROXY_OPTIONS autoProxyOptions,
out Interop.WinHttp.WINHTTP_PROXY_INFO proxyInfo)
{
if (TestControl.PACFileNotDetectedOnNetwork)
{
proxyInfo.AccessType = WINHTTP_ACCESS_TYPE_NO_PROXY;
proxyInfo.Proxy = IntPtr.Zero;
proxyInfo.ProxyBypass = IntPtr.Zero;
TestControl.LastWin32Error = (int)Interop.WinHttp.ERROR_WINHTTP_AUTODETECTION_FAILED;
return false;
}
proxyInfo.AccessType = Interop.WinHttp.WINHTTP_ACCESS_TYPE_NAMED_PROXY;
proxyInfo.Proxy = Marshal.StringToHGlobalUni(FakeRegistry.WinInetProxySettings.Proxy);
proxyInfo.ProxyBypass = IntPtr.Zero;
return true;
}
开发者ID:nnyamhon,项目名称:corefx,代码行数:22,代码来源:FakeInterop.cs
示例16: WinHttpSetTimeouts
public static bool WinHttpSetTimeouts(
SafeWinHttpHandle handle,
int resolveTimeout,
int connectTimeout,
int sendTimeout,
int receiveTimeout)
{
return true;
}
开发者ID:nnyamhon,项目名称:corefx,代码行数:9,代码来源:FakeInterop.cs
示例17: WinHttpQueryAuthSchemes
public static bool WinHttpQueryAuthSchemes(
SafeWinHttpHandle requestHandle,
out uint supportedSchemes,
out uint firstScheme,
out uint authTarget)
{
supportedSchemes = 0;
firstScheme = 0;
authTarget = 0;
return true;
}
开发者ID:nnyamhon,项目名称:corefx,代码行数:12,代码来源:FakeInterop.cs
示例18: SetWinHttpCredential
private void SetWinHttpCredential(
SafeWinHttpHandle requestHandle,
ICredentials credentials,
Uri uri,
uint authScheme,
uint authTarget)
{
Debug.Assert(credentials != null);
Debug.Assert(authScheme != 0);
Debug.Assert(authTarget == Interop.WinHttp.WINHTTP_AUTH_TARGET_PROXY ||
authTarget == Interop.WinHttp.WINHTTP_AUTH_TARGET_SERVER);
NetworkCredential networkCredential = credentials.GetCredential(uri, s_authSchemeStringMapping[authScheme]);
// Skip if no credentials or this is the default credential.
if (networkCredential == null || networkCredential == CredentialCache.DefaultNetworkCredentials)
{
return;
}
string userName = networkCredential.UserName;
string password = networkCredential.Password;
string domain = networkCredential.Domain;
// WinHTTP does not support a blank username. So, we will throw an exception.
if (string.IsNullOrEmpty(userName))
{
// TODO: Add error message.
throw new InvalidOperationException();
}
if (!string.IsNullOrEmpty(domain))
{
userName = domain + "\\" + userName;
}
if (!Interop.WinHttp.WinHttpSetCredentials(
requestHandle,
authTarget,
authScheme,
userName,
password,
IntPtr.Zero))
{
WinHttpException.ThrowExceptionUsingLastError();
}
}
开发者ID:JerryForNet,项目名称:corefx,代码行数:47,代码来源:WinHttpHandler.cs
示例19: ProcessResponse
private void ProcessResponse(
RequestState state,
SafeWinHttpHandle requestHandle,
ref uint proxyAuthScheme,
ref uint serverAuthScheme,
out bool retryRequest)
{
retryRequest = false;
// Check the status code and retry the request applying credentials if needed.
var statusCode = (HttpStatusCode)GetResponseHeaderNumberInfo(
requestHandle,
Interop.WinHttp.WINHTTP_QUERY_STATUS_CODE);
uint supportedSchemes = 0;
uint firstSchemeIgnored = 0;
uint authTarget = 0;
Uri uri = state.RequestMessage.RequestUri;
switch (statusCode)
{
case HttpStatusCode.Unauthorized:
if (state.ServerCredentials == null || state.LastStatusCode == HttpStatusCode.Unauthorized)
{
// Either we don't have server credentials or we already tried
// to set the credentials and it failed before.
// So we will let the 401 be the final status code returned.
break;
}
state.LastStatusCode = statusCode;
// Determine authorization scheme to use. We ignore the firstScheme
// parameter which is included in the supportedSchemes flags already.
// We pass the schemes to ChooseAuthScheme which will pick the scheme
// based on most secure scheme to least secure scheme ordering.
if (!Interop.WinHttp.WinHttpQueryAuthSchemes(
requestHandle,
out supportedSchemes,
out firstSchemeIgnored,
out authTarget))
{
WinHttpException.ThrowExceptionUsingLastError();
}
// Verify the authTarget is for server authentication only.
if (authTarget != Interop.WinHttp.WINHTTP_AUTH_TARGET_SERVER)
{
// TODO: Protocol violation. Add detailed error message.
throw new InvalidOperationException();
}
serverAuthScheme = ChooseAuthScheme(supportedSchemes);
if (serverAuthScheme != 0)
{
SetWinHttpCredential(
requestHandle,
state.ServerCredentials,
uri,
serverAuthScheme,
authTarget);
retryRequest = true;
}
break;
case HttpStatusCode.ProxyAuthenticationRequired:
if (state.LastStatusCode == HttpStatusCode.ProxyAuthenticationRequired)
{
// We tried already to set the credentials.
break;
}
state.LastStatusCode = statusCode;
// Determine authorization scheme to use. We ignore the firstScheme
// parameter which is included in the supportedSchemes flags already.
// We pass the schemes to ChooseAuthScheme which will pick the scheme
// based on most secure scheme to least secure scheme ordering.
if (!Interop.WinHttp.WinHttpQueryAuthSchemes(
requestHandle,
out supportedSchemes,
out firstSchemeIgnored,
out authTarget))
{
WinHttpException.ThrowExceptionUsingLastError();
}
// Verify the authTarget is for proxy authentication only.
if (authTarget != Interop.WinHttp.WINHTTP_AUTH_TARGET_PROXY)
{
// TODO: Protocol violation. Add detailed error message.
throw new InvalidOperationException();
}
proxyAuthScheme = ChooseAuthScheme(supportedSchemes);
retryRequest = true;
break;
default:
if (_preAuthenticate && serverAuthScheme != 0)
{
//.........这里部分代码省略.........
开发者ID:JerryForNet,项目名称:corefx,代码行数:101,代码来源:WinHttpHandler.cs
示例20: PreAuthenticateRequest
private void PreAuthenticateRequest(
RequestState state,
SafeWinHttpHandle requestHandle,
uint proxyAuthScheme)
{
// Set proxy credentials if we have them.
// If a proxy authentication challenge was responded to, reset
// those credentials before each SendRequest, because the proxy
// may require re-authentication after responding to a 401 or
// to a redirect. If you don't, you can get into a
// 407-401-407-401- loop.
if (proxyAuthScheme != 0)
{
SetWinHttpCredential(
requestHandle,
state.Proxy == null ? _defaultProxyCredentials : state.Proxy.Credentials,
state.RequestMessage.RequestUri,
proxyAuthScheme,
Interop.WinHttp.WINHTTP_AUTH_TARGET_PROXY);
}
// Apply pre-authentication headers for server authentication?
if (_preAuthenticate)
{
uint authScheme;
NetworkCredential serverCredentials;
if (GetServerCredentialsFromCache(
state.RequestMessage.RequestUri,
out authScheme,
out serverCredentials))
{
SetWinHttpCredential(
requestHandle,
serverCredentials,
state.RequestMessage.RequestUri,
authScheme,
Interop.WinHttp.WINHTTP_AUTH_TARGET_SERVER);
state.LastStatusCode = HttpStatusCode.Unauthorized; // Remember we already set the creds.
}
}
}
开发者ID:JerryForNet,项目名称:corefx,代码行数:41,代码来源:WinHttpHandler.cs
注:本文中的Interop.WinHttp.SafeWinHttpHandle类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论