Is it possible to pass parameters with an HTTP
get request? If so, how should I then do it? I have found an HTTP
post requst (link). In that example the string postData
is sent to a webserver. I would like to do the same using get instead. Google found this example on HTTP
get here. However no parameters are sent to the web server.
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
In a GET request, you pass parameters as part of the query string.
The WebRequest object seems like too much work for me. I prefer to use the WebClient control.
To use this function you just need to create two NameValueCollections holding your parameters and request headers.
Consider the following function:
Add your querystring parameters (if required) as a NameValueCollection like so.
Add your http headers (if required) as a NameValueCollection like so.
My preferred way is this. It handles the escaping and parsing for you.
First
WebClient
is easier to use; GET arguments are specified on the query-string - the only trick is to remember to escape any values:You can also pass value directly via URL.
If you want to call method
public static void calling(string name){....}
then you should call using
HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create("http://localhost:****/Report/calling?name=Priya); webrequest.Method = "GET"; webrequest.ContentType = "application/text";
Just make sure you are using
?Object = value
in URL