Hi ofiras,
Envelop the code by "try ... catch... " to catch WebException exception.
I need exception.Message, exception.Response...Stream and exception.Status
to analyse the exception.
Kind Regards, Alex Meleta
[TechBlog]
http://devkids.blogspot.com
Hi ofiras,
I try to get response, and it says "The remote server returned an
error:
(403) Forbidden.", and in the details it is written "Connection:
close".
The server understood the request but refused to fulfil (may be
access to the page is forbidden or request is incorrect (quesry
format or something else)). Server should describe the reason for the
refusal in the entity.
Some info about status
codes:
http://support.microsoft.com/kb/318380/en-ushttp://htmlhelp.com
/tools/valet/http.txt
Kind Regards, Alex Meleta
[TechBlog]
http://devkids.blogspot.com
o> The remote server
o>
o> So, isn't there any way of getting the source code from it? For
o> example:
o>
o> WebRequest webRequest = WebRequest.Create("
http://en.wikipedia.org/
o> wiki/Ofir");
o> WebResponse webResponse = webRequest.GetResponse();
o> StreamReader streamReader = new
o> StreamReader(webResponse.GetResponseStream());
o> string html = streamReader.ReadToEnd();
o> This site gives an exception, but this:
o>
http://en.wikipedia.org/wiki/A
o> doesn't.
o> Is there a way of getting the source code?
o> Please help,
o> Ofir.
The information is:
Message: "The remote server returned an error: (403) Forbidden."
Response: System.Net.HttpWebResponse
Response Headers:
"X-Cache: MISS from sq18.wikimedia.org,MISS from
knsq2.knams.wikimedia.org,MISS from knsq2.knams.wikimedia.org
X-Cache-Lookup: MISS from sq18.wikimedia.org:3128,MISS from
knsq2.knams.wikimedia.org:3128,MISS from knsq2.knams.wikimedia.org:80
Connection: close
Content-Length: 35
Content-Type: text/html
Date: Sat, 07 Jul 2007 19:30:07 GMT
Server: Apache
Via: 1.0 sq18.wikimedia.org:3128 (squid/2.6.STABLE12), 1.0
knsq2.knams.wikimedia.org:3128 (squid/2.6.STABLE12), 1.0
knsq2.knams.wikimedia.org:80 (squid/2.6.STABLE12)
X-Powered-By: PHP/5.1.4"
Status: System.Net.WebExceptionStatus.ProtocolError
Stream: Didn't find it...
StackTrack: "at System.Net.HttpWebRequest.GetResponse()\r\n at
wikidic.Form1..ctor() in E:\\c#\\wikidic\\wikidic\\Form1.cs:line 24\r
\n at wikidic.Program.Main() in E:\\c#\\wikidic\\wikidic\
\Program.cs:line 17\r\n at
System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)\r
\n at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)\r\n at
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()\r
\n at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
\r\n at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)\r\n at
System.Threading.ThreadHelper.ThreadStart()"
Thanks for helping,
Ofir.