0

我是 .Net 和网络服务的新手..我喜欢通过 url 传递 id..如何做到这一点?无论是发布还是获取方法?指导我

string url = "http://XXXXX//"+id=22;

WebRequest request = WebRequest.Create(url);
request.Proxy.Credentials = new NetworkCredential(xxxxx);
request.Credentials = CredentialCache.DefaultCredentials;
//add properties
request.Method = "GET";
request.ContentType = "application/json";
//convert 
byte[] byteArray = Encoding.UTF8.GetBytes(data);
request.ContentLength = byteArray.Length;
//post data
Stream streamdata = request.GetRequestStream();
streamdata.Write(byteArray, 0, byteArray.Length);
streamdata.Close();
//response
WebResponse response = request.GetResponse();
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
// Clean up the streams and the response.
reader.Close();
response.Close();
4

1 回答 1

0

If you just want to build the URL with parameters (ref: Query String) then you can simply do:

string url = string.Format("http://www.google.com/?id={0}",22);

You can check this url, Passing variables between pages using QueryString at Code Project

于 2012-11-05T11:09:28.387 回答