Click here to Skip to main content
15,881,856 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Sir !
i'm new to web services. i've written a code for web request.
but it's giving web exception
the code is;
C#
using System;
using System.Collections.Generic;
//using System.Linq;
using System.Net;
using System.IO;
using System.Text;

namespace webrequest_demo.System.Net
{
    public class webrequestExample
    {
        public static void Main(String[] args)
        {
            try
            {

                WebRequest webr = WebRequest.Create(" "http://www.contoso.com/default.html"");
                webr.Credentials = CredentialCache.DefaultCredentials;
                WebResponse webresp = webr.GetResponse();
                Console.WriteLine(((HttpWebResponse)webresp).StatusDescription);
                Stream ds = webresp.GetResponseStream();
                StreamReader str = new StreamReader(ds);
                string responseFrommServer = str.ReadToEnd();
                str.Close();
                webresp.Close();

            }
            catch (WebException wex)
            {
                Console.WriteLine(wex.Message);
                Console.WriteLine(wex.Response);
                Console.WriteLine(wex.StackTrace);
                Console.WriteLine(wex.InnerException);
            }
            //finally
            //{


            //}

            Console.ReadLine();
        }
    }
}


what is contoso.com
Posted
Updated 3-Mar-14 7:39am
v2
Comments
Sergey Alexandrovich Kryukov 3-Mar-14 12:36pm    
Who likes guesswork? Exception? What exception, where?
—SA
[no name] 3-Mar-14 13:57pm    
You are new in web service it doesn't problem. Problem is just copy a code and paste is project without understanding. Understand each and every line code before paste in your project. Go to the link to know what is WebRequest.create(url).

http://msdn.microsoft.com/en-us/library/0aa3d588%28v=vs.110%29.aspx

1 solution

Change this line as below and test again

WebRequest webr = WebRequest.Create(@"http://www.contoso.com/default.html");
 
Share this answer
 
Comments
tusharkaushik 5-Mar-14 6:09am    
i've done but not result

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900