2012-11-05 39 views
0

新的.Net和Web服務..我喜歡通過URL傳遞id ..如何做到這一點?是否它完成後或獲取方法?引導我如何使用網絡請求傳遞值在url中GET方法asp.net

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(); 

回答

相關問題