WebRequest.GetResponse() - does not work properly

P

Piotrekk

Hi

WebRequest req = WebRequest.Create(url);
WebResponse res = (WebResponse)req.GetResponse();

My url is:

http://192.168.1.56/FileManagerWebService/Download.aspx?Name=test\Certification
- Microsoft - 70-315 70-316 70-320 - Visual C# Net Certification All-
In-One Exam Guide.pdf&SessionID=e36f3a1f-1d6a-4bd6-9c63-bd0ef5f313a3

I have used port sniffer to detect what is on the communication
channel:

GET /FileManagerWebService/Download.aspx?Name=test%5CCertification%20-
%20Microsoft%20-%2070-315%2070-316%2070-320%20-%20Visual%20C HTTP/1.1

My question is: why GET parameter was cut at the "#" character?

Best Regards
PK
 
J

Jon Skeet [C# MVP]

WebRequest req = WebRequest.Create(url);
WebResponse res = (WebResponse)req.GetResponse();

My url is:

http://192.168.1.56/FileManagerWebService/Download.aspx?Name=test\Certification
- Microsoft - 70-315 70-316 70-320 - Visual C# Net Certification All-
In-One Exam Guide.pdf&SessionID=e36f3a1f-1d6a-4bd6-9c63-bd0ef5f313a3

I have used port sniffer to detect what is on the communication
channel:

GET /FileManagerWebService/Download.aspx?Name=test%5CCertification%20-
%20Microsoft%20-%2070-315%2070-316%2070-320%20-%20Visual%20C HTTP/1.1

My question is: why GET parameter was cut at the "#" character?

Because anything after a # in a URL is used to tell a browser which
point in the document to look at. You need to escape the #, basically,
as %23.

Jon
 
P

Piotrekk

Because anything after a # in a URL is used to tell a browser which
point in the document to look at. You need to escape the #, basically,
as %23.

Jon

Thank you Jon. Are there more characters like # that could cause the
similar situation?
 
M

Marc Gravell

You might find Uri.EscapeDataString() handy;

Marc


string name = @"test\Certification - Microsoft - 70-315 70-316 70-320 -
Visual C# Net Certification All-In-One Exam Guide.pdf",
sessionID = @"e36f3a1f-1d6a-4bd6-9c63-bd0ef5f313a3";

string uri = string.Format(

@"http://192.168.1.56/FileManagerWebService/Download.aspx?Name={0}&SessionID={1}",
Uri.EscapeDataString(name),
Uri.EscapeDataString(sessionID));
 
Top