当前位置: 首页>>代码示例>>C#>>正文


C# HttpWebRequest.SetBasicAuth方法代码示例

本文整理汇总了C#中System.Net.HttpWebRequest.SetBasicAuth方法的典型用法代码示例。如果您正苦于以下问题:C# HttpWebRequest.SetBasicAuth方法的具体用法?C# HttpWebRequest.SetBasicAuth怎么用?C# HttpWebRequest.SetBasicAuth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.HttpWebRequest的用法示例。


在下文中一共展示了HttpWebRequest.SetBasicAuth方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetAsync

 /// <summary>Attempts to get data from a web request.</summary>
 /// <param name="request">The HTTP web request.</param>
 /// <param name="method">The OneAll supported HTTP method to use.</param>
 /// <param name="creds">The <see cref="Credential"/> used to authenticate the call, or null for calls not requiring authentication.</param>
 /// <param name="callBack">The call-back to invoke after the request is complete.</param>
 /// <param name="state">The initial state object provided.</param>
 private static void GetAsync(HttpWebRequest request, OneAllMethod method, Credential creds, BinaryReceivedHandler callBack, object state)
 {
     request.SetHTTPMethod(method);
     request.SetBasicAuth(creds);
     request.BeginGetResponse(OnRequestCompleted, new BinaryWebClientState()
     {
         Request = request,
         Callback = callBack,
         State = state
     });
 }
开发者ID:K232,项目名称:OneAll,代码行数:17,代码来源:BinaryWebClient.cs

示例2: GetSync

 /// <summary>Attempts to get data from a web request.</summary>
 /// <param name="request">The HTTP web request.</param>
 /// <param name="method">The OneAll supported HTTP method to use.</param>
 /// <param name="creds">The <see cref="Credential"/> used to authenticate the call, or null for calls not requiring authentication.</param>
 /// <returns>The binary data from the request.</returns>
 private static byte[] GetSync(HttpWebRequest request, OneAllMethod method, Credential creds)
 {
     request.SetHTTPMethod(method);
     request.SetBasicAuth(creds);
     return ReadResponse(request);
 }
开发者ID:K232,项目名称:OneAll,代码行数:11,代码来源:BinaryWebClient.cs

示例3: PostSync

        /// <summary>Attempts to get data from a web request.</summary>
        /// <param name="request">The HTTP web request.</param>
        /// <param name="method">The OneAll supported HTTP method to use.</param>
        /// <param name="creds">The <see cref="Credential"/> used to authenticate the call, or null for calls not requiring authentication.</param>
        /// <param name="data">The raw data to be posted.</param>
        /// <returns>The binary data from the request.</returns>
        private static byte[] PostSync(HttpWebRequest request, OneAllMethod method, Credential creds, byte[] data)
        {
            request.ContentType = OneAllConstants.HTTP_CONTENTTYPE_FORMURLENCODE;
            request.SetHTTPMethod(method);
            request.SetBasicAuth(creds);

            using (Stream stream = request.GetRequestStream())
            {
                byte[] buffer = new byte[data.Length];
                Array.Copy(data, buffer, buffer.Length);

                stream.Write(buffer, 0, buffer.Length);
                stream.Flush();

                Array.Clear(buffer, 0, buffer.Length);
                buffer = null;
            }

            return ReadResponse(request);
        }
开发者ID:K232,项目名称:OneAll,代码行数:26,代码来源:BinaryWebClient.cs

示例4: PostAsync

        /// <summary>Attempts to get data from a web request.</summary>
        /// <param name="request">The HTTP web request.</param>
        /// <param name="method">The OneAll supported HTTP method to use.</param>
        /// <param name="creds">The <see cref="Credential"/> used to authenticate the call, or null for calls not requiring authentication.</param>
        /// <param name="data">The raw data to be posted.</param>
        /// <param name="callBack">The call-back to invoke after the request is complete.</param>
        /// <param name="state">The initial state object provided.</param>
        private static void PostAsync(HttpWebRequest request, OneAllMethod method, Credential creds, byte[] data, BinaryReceivedHandler callBack, object state)
        {
            request.ContentType = OneAllConstants.HTTP_CONTENTTYPE_FORMURLENCODE;
            request.SetHTTPMethod(method);
            request.SetBasicAuth(creds);

            request.BeginGetRequestStream(OnRequestStreamObtained, new BinaryWebClientState()
            {
                Request = request,
                Callback = callBack,
                State = state,
                Data = data
            });
        }
开发者ID:K232,项目名称:OneAll,代码行数:21,代码来源:BinaryWebClient.cs


注:本文中的System.Net.HttpWebRequest.SetBasicAuth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。