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


C# HttpWebRequest类代码示例

本文整理汇总了C#中HttpWebRequest的典型用法代码示例。如果您正苦于以下问题:C# HttpWebRequest类的具体用法?C# HttpWebRequest怎么用?C# HttpWebRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: AddRequestXml

    private void AddRequestXml(string url, HttpWebRequest req)
    {
        Stream stream = (Stream)req.GetRequestStream();
        using (XmlTextWriter writer = new XmlTextWriter(stream, Encoding.UTF8))
        {
            writer.WriteStartDocument(true);
            writer.WriteStartElement("methodCall");
            writer.WriteElementString("methodName", "pingback.ping");
            writer.WriteStartElement("params");

            writer.WriteStartElement("param");
            writer.WriteStartElement("value");
            writer.WriteElementString("string", Blogsa.Url);
            writer.WriteEndElement();
            writer.WriteEndElement();

            writer.WriteStartElement("param");
            writer.WriteStartElement("value");
            writer.WriteElementString("string", url);
            writer.WriteEndElement();
            writer.WriteEndElement();

            writer.WriteEndElement();
            writer.WriteEndElement();
        }
    }
开发者ID:Blogsa,项目名称:blogsa,代码行数:26,代码来源:SendPings.cs

示例2: set_option

            private void set_option(string rel)
            {
                string url = "http://" + URI + "/web/cgi-bin/hi3510/param.cgi?"+rel+"&usr=" + Login + "&pwd=" + Password;

                Console.WriteLine("Call "+url+" - start");
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create (url);
                req.KeepAlive = false;
                req.Headers.Add ("Accept-Encoding", "gzip,deflate");
                req.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
                req.UseDefaultCredentials = true;
                req.Credentials = new NetworkCredential (Login, Password);
                req.Proxy = null;
                req.Timeout = 1000;
                WebResponse resp = null;
                req.KeepAlive = false;

                pause = true;
                try{
                    resp = req.GetResponse();
                    resp.Close();
                } catch(Exception e) {
                    Console.WriteLine (e.Message);
                }

                req = null;

                Console.WriteLine("Call "+url+" - end");
            }
开发者ID:rastabaddon,项目名称:QCCTV,代码行数:28,代码来源:JPGDriver.cs

示例3: Request

    public void Request(string url)
    {
        Stopwatch timer = new Stopwatch();
        StringBuilder respBody = new StringBuilder();

        this.request = (HttpWebRequest)WebRequest.Create(url);

        try {
            timer.Start();
            this.response = (HttpWebResponse)this.request.GetResponse();
            byte[] buf = new byte[8192];
            Stream respStream = this.response.GetResponseStream();
            int count = 0;
            do {
                count = respStream.Read(buf, 0, buf.Length);
                if (count != 0)
                    respBody.Append(Encoding.ASCII.GetString(buf, 0, count));
            }
            while (count > 0);
            timer.Stop();

            this.responseBody = respBody.ToString();
            this.statusCode = (int)(HttpStatusCode)this.response.StatusCode;
            this.responseTime = timer.ElapsedMilliseconds / 1000.0;
        } catch (WebException ex) {
            this.response = (HttpWebResponse)ex.Response;
            this.responseBody = "No Server Response";
            this.escapedBody = "No Server Response";
            this.responseTime = 0.0;
        }
    }
开发者ID:Arrem,项目名称:MCForge-MCLawl,代码行数:31,代码来源:HTTPGet.cs

示例4: State

	public State (int id, HttpWebRequest req)
	{
		this.id = id;
		request = req;
		handle = new ManualResetEvent (false);
		handleList.Add (handle);
	}
开发者ID:Jakosa,项目名称:MonoLibraries,代码行数:7,代码来源:tlssave.cs

示例5: OnSendingHeaders

    // fields

    // constructors

    // properties

    // methods

        internal static void OnSendingHeaders(HttpWebRequest httpWebRequest) {
            GlobalLog.Print("CookieModule::OnSendingHeaders()");
            try {
                if (httpWebRequest.CookieContainer == null) {
                    return;
                }
                //
                // remove all current cookies. This could be a redirect
                //
                httpWebRequest.Headers.RemoveInternal(HttpKnownHeaderNames.Cookie);
                //
                // add in the new headers from the cookie container for this request
                //
                string optCookie2;
                string cookieString = httpWebRequest.CookieContainer.GetCookieHeader(
                    httpWebRequest.GetRemoteResourceUri(), out optCookie2);

                if (cookieString.Length > 0) {
                    GlobalLog.Print("CookieModule::OnSendingHeaders() setting Cookie header to:[" + cookieString + "]");
                    httpWebRequest.Headers[HttpKnownHeaderNames.Cookie] = cookieString;

//<





                }
            }
            catch {
            }

        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:41,代码来源:_CookieModule.cs

示例6: OnReceivedHeaders

        internal static void OnReceivedHeaders(HttpWebRequest httpWebRequest) {
            GlobalLog.Print("CookieModule.OnReceivedHeaders()");
            //
            // if the app doesn't want us to handle cookies then there's nothing
            // to do. Note that we're leaving open the possibility that these
            // settings could be changed between the request being made and the
            // response received
            //
            try {
                if (httpWebRequest.CookieContainer == null) {
                    return;
                }

                //
                // add any received cookies for this response to the container
                //
                HttpWebResponse response = (HttpWebResponse)httpWebRequest._HttpResponse;
                CookieCollection cookies = null;
                try {
                    string cookieString = response.Headers[HttpKnownHeaderNames.SetCookie];
                    GlobalLog.Print("CookieModule::OnSendingHeaders() received Set-Cookie:[" + cookieString + "]");
                    if ((cookieString != null) && (cookieString.Length > 0)) {
                        cookies = httpWebRequest.CookieContainer.CookieCutter(
                                                            response.ResponseUri,
                                                            HttpKnownHeaderNames.SetCookie,
                                                            cookieString,
                                                            false);
                    }
                }
                catch {
                }

                try {
                    string cookieString = response.Headers[HttpKnownHeaderNames.SetCookie2];
                    GlobalLog.Print("CookieModule::OnSendingHeaders() received Set-Cookie2:[" + cookieString + "]");
                    if ((cookieString != null) && (cookieString.Length > 0)) {
                        CookieCollection cookies2 = httpWebRequest.CookieContainer.CookieCutter(
                                                                    response.ResponseUri,
                                                                    HttpKnownHeaderNames.SetCookie2,
                                                                    cookieString,
                                                                    false);
                        if (cookies != null && cookies.Count != 0) {
                            cookies.Add(cookies2);
                        }
                        else {
                            cookies = cookies2;
                        }
                    }
                }
                catch {
                }
                if (cookies != null) {
                    response.Cookies = cookies;
                }
            }
            catch {
            }

        }
开发者ID:ArildF,项目名称:masters,代码行数:59,代码来源:_cookiemodule.cs

示例7: InitializeRequest

 public static void InitializeRequest(HttpWebRequest request)
 {
     request.Headers.Add("aw-tenant-code", API_TENANT_CODE);
     request.Credentials = new NetworkCredential(USER_NAME, PASSWORD);
     request.KeepAlive = false;
     request.AddRange(1024);
     request.Timeout = 10000;
 }
开发者ID:Curtisspope,项目名称:MDM_API_AW,代码行数:8,代码来源:DataRetrieval.cs

示例8: AssertRequestDefaults

 /// <summary>
 /// For every request, there are things we expect to remain constant. Verify that they do.
 /// </summary>
 /// <param name="request"></param>
 /// <param name="method"></param>
 public void AssertRequestDefaults(HttpWebRequest request, string method)
 {
     Assert.IsTrue(request.Address == new Uri(host));
     Assert.IsTrue(request.Headers.ToString() == "Authorization: Bearer\r\nContent-Type: application/json\r\n\r\n");
     Assert.IsTrue(request.Host == "localhost");
     Assert.IsTrue(request.KeepAlive == true);
     Assert.IsTrue(request.Method == method);
     Assert.IsTrue(request.Timeout == 90000);
 }
开发者ID:pokitdok,项目名称:pokitdok-csharp,代码行数:14,代码来源:PlatformClientTest.cs

示例9: getResponse

            protected HttpWebResponse getResponse(HttpWebRequest request)
            {
                // execute the request

                    HttpWebResponse response = (HttpWebResponse)
                        request.GetResponse();

                    return response;
            }
开发者ID:niranjan-nagaraju,项目名称:SMART-Downloader,代码行数:9,代码来源:BasicDownloader.cs

示例10: InitGCMClient

    private void InitGCMClient()
    {
        //對GCM Server發出Http post
        gcmRequest = WebRequest.Create(GCM_URI) as HttpWebRequest;
        gcmRequest.ContentType = "application/json";
        gcmRequest.UserAgent = "Android GCM Message Sender Client 1.0";
        gcmRequest.Method = "POST";

        // Credential info
        gcmRequest.Headers.Add("Authorization", "key=" + APIKey);
    }
开发者ID:asaki0510,项目名称:AlarmRuleSet,代码行数:11,代码来源:GCMSender.cs

示例11: GetReadStreamResult

 /// <summary>
 /// Constructs a new async result object
 /// </summary>
 /// <param name="source">The source of the operation.</param>
 /// <param name="method">Name of the method which is invoked asynchronously.</param>
 /// <param name="request">The <see cref="HttpWebRequest"/> object which is wrapped by this async result.</param>
 /// <param name="callback">User specified callback for the async operation.</param>
 /// <param name="state">User state for the async callback.</param>
 internal GetReadStreamResult(
     object source, 
     string method, 
     HttpWebRequest request, 
     AsyncCallback callback, 
     object state)
     : base(source, method, callback, state)
 {
     Debug.Assert(request != null, "Null request can't be wrapped to a result.");
     this.request = request;
     this.Abortable = request;
 }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:20,代码来源:GetReadStreamResult.cs

示例12: createDataStream

 public Stream createDataStream(Dictionary<string,string> body ,HttpWebRequest request)
 {
     string theBody = "";
     foreach(KeyValuePair<string,string> bodyPart in body){
         theBody = theBody + bodyPart.Key + "=" + bodyPart.Value + "&";
     }
     byte[] byteArray = Encoding.UTF8.GetBytes(theBody);
     request.ContentLength = byteArray.Length;
     Stream dataStream = request.GetRequestStream();
     dataStream.Write(byteArray, 0,byteArray.Length);
     dataStream.Close ();
     return dataStream;
 }
开发者ID:Nersle,项目名称:Unity,代码行数:13,代码来源:Postman.cs

示例13: AddProxyInfoToRequest

    public static HttpWebRequest AddProxyInfoToRequest(HttpWebRequest httpRequest, Uri proxyUri, string proxyId, string proxyPassword, string proxyDomain)
    {
        if (httpRequest != null)
            {

                WebProxy proxyInfo = new WebProxy();
                proxyInfo.Address = proxyUri;
                proxyInfo.BypassProxyOnLocal = true;
                proxyInfo.Credentials = new NetworkCredential(proxyId, proxyPassword, proxyDomain);
                httpRequest.Proxy = proxyInfo;

            }
            return httpRequest;
    }
开发者ID:blat001,项目名称:Achievement-Sherpa,代码行数:14,代码来源:DownloadHelper.cs

示例14: HttpWebRequestCore

		public HttpWebRequestCore (HttpWebRequest parent, Uri uri)
		{
			if (uri == null)
				throw new ArgumentNullException ("uri");

			this.uri = uri;
			if (parent == null) {
				// special case used for policy
				allow_read_buffering = true;
				method = "GET";
			} else {
				allow_read_buffering = parent.AllowReadStreamBuffering;
				method = parent.Method;
				headers = parent.Headers;
			}
		}
开发者ID:dfr0,项目名称:moon,代码行数:16,代码来源:HttpWebRequestCore.cs

示例15: GetResponse

    private string GetResponse(string url, ref HttpWebRequest request)
    {
        StringBuilder sb = new StringBuilder();
        Stream resStream = null;
        HttpWebResponse response = null;
        byte[] buf = new byte[8192];

        try
        {
            // execute the request
            response = (HttpWebResponse)request.GetResponse();

            // we will read data via the response stream
            resStream = response.GetResponseStream();
            string tempString = null;
            int count = 0;
            do
            {
                // fill the buffer with data
                count = resStream.Read(buf, 0, buf.Length);
                // make sure we read some data
                if (count != 0)
                {
                    // translate from bytes to ASCII text
                    tempString = Encoding.ASCII.GetString(buf, 0, count);
                    // continue building the string
                    sb.Append(tempString);
                }
            }
            while (count > 0); // any more data to read?
        }
        catch (Exception err)
        {
            String exc = err.Message;
        }
        finally
        {
            response.Close();
            resStream.Close();
        }

        return sb.ToString();
    }
开发者ID:KPratap,项目名称:PropSolutions,代码行数:43,代码来源:Testpage.aspx.cs


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