none
Need Extreme Help

    Question

  • public class GoogleUrlShortner
        {
            public static GoogleUrlReply Shorten(string longUrl, string apiKey = "")
            {
                string data = "{\"longUrl\":\"" + longUrl + "\"}";
                string gUrl = "https://www.googleapis.com/urlshortener/v1/url";
    
                if (!string.IsNullOrEmpty(apiKey)) gUrl += "?key=" + apiKey;
    
                string response = Post(gUrl, data);
                return FromJSON<GoogleUrlReply>(response);
    
            }
    
            
            public static GoogleUrlReply Expand(string shortUrl, string apiKey = "")
            {
                string gUrl = "https://www.googleapis.com/urlshortener/v1/url?shortUrl=" + shortUrl;
    
                if (!string.IsNullOrEmpty(apiKey)) gUrl += "&key=" + apiKey;
    
                string response = Get(gUrl);
                return FromJSON<GoogleUrlReply>(response);
            }
             
    
    
            public static string Get(string url)
            {
                WebClient web = new WebClient();
                
                    return web.(url);
                
            }
    
            private static string Post(string url, string data)
            {
                System.Net.WebRequest request1 = WebRequest.Create(url);
                request1.Method = "POST";
                request1.ContentType = "application/json";
    
                byte[] byteData = Encoding.UTF8.GetBytes(data);
    
                request1.ContentLength = byteData.Length;
    
                using (Stream s = request1.GetRequestStream())
                {
                    s.Write(byteData, 0, byteData.Length);
                    s.Close();
                }
    
                string replyData;
    
                using (HttpWebResponse response = (HttpWebResponse)request1.GetResponse())
                {
                    using (Stream dataStream = response.GetResponseStream())
                    {
                        using (StreamReader reader = new StreamReader(dataStream))
                        {
                            replyData = reader.ReadToEnd();
                        }
                    }
                }
    
                return replyData;
            }
    
            private static T FromJSON<T>(string input)
            {
                MemoryStream stream = new MemoryStream();
    
                try
                {
                    DataContractJsonSerializer jsSerializer = new DataContractJsonSerializer(typeof(T));
                    stream = new MemoryStream(Encoding.UTF8.GetBytes(input));
                    T obj = (T)jsSerializer.ReadObject(stream);
    
                    return obj;
                }
                finally
                {
                    stream.Close();
                    stream.Dispose();
                }
            }


    I am getting errors in webclient, webresponse and others

    pls rectify for me these erros...am extremely frustrated with WP7 coding

    Wednesday, June 22, 2011 2:39 PM

All replies