Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I am trying to get a response from a URL using the HttpWebRequest
object. This is my code below:
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(url);
WebResponse myResp = myReq.GetResponse();
Stream stream = myResp.GetResponseStream();
System.Drawing.Image oImg = System.Drawing.Image.FromStream(stream);

here my URL length is 2080 characters and I need to send up to 5000 characters. Is there any solutions for this scenario? Please let me know.

When I'm running the sample console application, I'm getting the following error:
"the remote server returned an error 404 not found at system.net.httpwebrequest.getresponse"

URL:
http://localhost/RestfulService/Service.svc/runPowershell?strQuery=<?xml version='1.0'?><wql host='10.10.10.10'' username='abcd' password='12545'><query id='0.' ><![CDATA[ Get-WmiObject -query 'select CSName from Win32_OperatingSystem']]></query><query id='1.' ><![CDATA[ Get-WmiObject -query 'select Caption from Win32_OperatingSystem ']]></query><query id='2.' ><![CDATA[ Get-WmiObject -query 'select CSDVersion from Win32_OperatingSystem']]></query><query id='3.' ><![CDATA[ Get-WmiObject -query 'select FreePhysicalMemory from Win32_OperatingSystem']]></query><query id='4.' ><![CDATA[ Get-WmiObject -query 'select TotalVisibleMemorySize from Win32_OperatingSystem']]></query><query id='5.' ><![CDATA[ Get-WmiObject -query 'select NumberOfProcesses from Win32_OperatingSystem']]></query><query id='6.' ><![CDATA[ Get-WmiObject -query 'select Size from Win32_DiskDrive']]></query><query id='7.' ><![CDATA[ Get-WmiObject -query 'select LoadPercentage from Win32_Processor']]></query><query id='8.1' ><![CDATA[ Get-WmiObject -query 'select FreePhysicalMemory from Win32_OperatingSystem']]></query><query id='8.2' ><![CDATA[ Get-WmiObject -query 'select TotalVisibleMemorySize from Win32_OperatingSystem']]></query><query id='9.1' ><![CDATA[ Get-WmiObject -query 'select FreeSpace from Win32_LogicalDisk']]></query><query id='9.2' ><![CDATA[ Get-WmiObject -query 'select size from Win32_LogicalDisk']]></query><query id='10.1' ><![CDATA[ Get-WmiObject -query 'select FreeSpace from Win32_LogicalDisk']]></query><query id='10.2' ><![CDATA[ Get-WmiObject -query 'select size from Win32_LogicalDisk']]></query><query id='11.1' ><![CDATA[ Get-WmiObject -query 'select FreeSpace from Win32_LogicalDisk']]></query><query id='11.2' ><![CDATA[ Get-WmiObject -query 'select size from Win32_LogicalDisk']]></query></wql>

URL Lenght: 2371
Posted
Updated 5-Dec-19 21:47pm
v5
Comments
Sandeep Mewara 16-Feb-11 1:48am    
I doubt but lets see other responses. URL length is just too much.
Abdul Quader Mamun 16-Feb-11 5:07am    
Complex URL. Not Understandable.

You have invalid characters in your query string.
On client side you need to escape it before you send request by using
Uri.EscapeUriString(string) or
Uri.EscapeDataString(string)
Both these methods are limited to 32766 characters in input strings.

The limitation could also be on service side.
If your service is hosted in IIS, I think default max query string is about 4KB.

For IIS 7 you can change maximum allowed url and query string length:
appcmd set config /section:requestfiltering /requestlimits.maxurl:<size in bytes>
and
appcmd set config /section:requestfiltering /requestlimits.maxquerystring:<size in bytes>

You can find more details here[^].
You can also use IIS Manager as described here[^]
 
Share this answer
 
v3
Comments
laxman2jasmi 21-Feb-11 5:18am    
hi, this is working fine in Windows XP Operating system. but it is not working in windows 7(IIS 7.0). Please let me know if any solutions for this
sjelen 21-Feb-11 6:04am    
I've updated solution with IIS configuration details you could try.
laxman2jasmi 21-Feb-11 6:55am    
Thank you very much
XML
Request Filtering is a built-in security feature that was introduced in Internet Information Services (IIS) 7.0, and replaces much of the functionality that was available through the UrlScan add-on for IIS 6.0. All of the settings for the request filtering feature are located within the <requestFiltering> element, which contains several child elements for each of the following feature areas:



1- Go to IIS.
2-Click on "Request Filtering"
3- Right Click and select Edit Feature Settings
4- Adjust Request Limits

Adjust Request Limits is where the limits to length of the request and the lenth of the query string are set.
 
Share this answer
 
v2

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