Logo Search packages:      
Sourcecode: tasque version File versions  Download package

string RtmNet::Rtm::DoGetResponse ( string  url,
string  variables 
) [inline, private]

A private method which performs the actual HTTP web request if the details are not found within the cache.

Parameters:
url The URL to download.
variables The query string parameters to be added to the end of the URL.
Returns:
A RtmNet.Response object.
If the final length of the URL would be greater than 2000 characters then they are sent as part of the body instead.

Definition at line 209 of file Rtm.cs.

References HttpTimeout, and Proxy.

            {
                  HttpWebRequest req = null;
                  HttpWebResponse res = null;

                  if( variables.Length < 2000 )
                  {
                        url += "?" + variables;
                        variables = "";
                  }

                  // Initialise the web request
                  req = (HttpWebRequest)HttpWebRequest.Create(url);
                  req.Method = "POST";

                  if (req.Method == "POST") req.ContentLength = variables.Length;

                  req.UserAgent = UserAgent;
                  if( Proxy != null ) req.Proxy = Proxy;
                  req.Timeout = HttpTimeout;
                  req.KeepAlive = false;
                  if (variables.Length > 0)
                  {
                        req.ContentType = "application/x-www-form-urlencoded";
                        StreamWriter sw = null;
                        try
                        {
                              sw = new StreamWriter(req.GetRequestStream());
                              sw.Write(variables);
                              sw.Close();
                        }
                        catch(WebException ex)
                        {
                              throw new RtmWebException(ex.Message, ex);
                        }
                        finally
                        {
                              if (sw != null)
                                    sw.Close();
                        }
                  }
                  else
                  {
                        // This is needed in the Compact Framework
                        // See for more details: http://msdn2.microsoft.com/en-us/library/1afx2b0f.aspx
                        req.GetRequestStream().Close();
                  }

                  try
                  {
                        // Get response from the internet
                        res = (HttpWebResponse)req.GetResponse();
                  }
                  catch(WebException ex)
                  {
                        if( ex.Status == WebExceptionStatus.ProtocolError )
                        {
                              HttpWebResponse res2 = (HttpWebResponse)ex.Response;
                              if( res2 != null )
                              {
                                    throw new RtmWebException(String.Format("HTTP Error {0}, {1}", (int)res2.StatusCode, res2.StatusDescription), ex);
                              }
                        }
                        throw new RtmWebException(ex.Message, ex);
                  }

                  string responseString = string.Empty;

                  using (StreamReader sr = new StreamReader(res.GetResponseStream()))
                  {
                        responseString = sr.ReadToEnd();
                  }

                  return responseString;
            }


Generated by  Doxygen 1.6.0   Back to index