简体   繁体   中英

Receive data in C# from web service

I want to receive data from this URL http://XXXXXX:7777/online?user=ir-U-butaneco&pass=ir-Ue724679821pars6843560G1P1S (web server continuously sends data).

I want to write a program in C# that reads the data and stores it in SQL. I don't have any data about the web service also WSDL description.

Thanks for your help

I wrote this code:

WebRequest request = WebRequest.Create("http://XXXX:7777/online?user=ir-U-butaneco&pass=ir-Ue724679821pars6843560G1P1S");
request.Method = "GET";

WebResponse response = request.GetResponse();

Console.WriteLine("Content type is {0}", response.ContentType);
Console.WriteLine(((HttpWebResponse)response).StatusDescription);

Stream dataStream = request.GetRequestStream();    <-- error 
dataStream = response.GetResponseStream();

StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();

Console.WriteLine(responseFromServer);

I get this error:

Cannot send a content-body with this verb-type

To receive data from a website you will need to make a HTTP GET request. Please check the answer provided by @Aydin Adn in this post: C# how to properly make a http web GET request

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