简体   繁体   中英

How to make a http GET request FROM a WCF web service

There are tons of information about how to make a GET request TO a WCF service.
But I need to make a http GET request FROM a WCF web service to some 3rd party server that provides some service I need.
So, how do I do this?

use the .net WebRequest object:

 public class WebRequestGetExample { public static void Main () { // Create a request for the URL. WebRequest request = WebRequest.Create ("http://www.contoso.com/default.html"); // If required by the server, set the credentials. request.Credentials = CredentialCache.DefaultCredentials; // Get the response. HttpWebResponse response = (HttpWebResponse)request.GetResponse (); // Display the status. Console.WriteLine (response.StatusDescription); // 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 (); // Display the content. Console.WriteLine (responseFromServer); // Cleanup the streams and the response. reader.Close (); dataStream.Close (); response.Close (); } } 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM