Vydělávej až 160.000 Kč měsíčně! Akreditované rekvalifikační kurzy s garancí práce od 0 Kč. Více informací.
Hledáme nové posily do ITnetwork týmu. Podívej se na volné pozice a přidej se do nejagilnější firmy na trhu - Více informací.
Avatar
madewman
Člen
Avatar
madewman:26.6.2019 11:31
{
          // Create a request using a URL that can receive a post.
          WebRequest request = WebRequest.Create("http://www.contoso.com/PostAccepter.aspx");
          // Set the Method property of the request to POST.
          request.Method = "POST";
          // Create POST data and convert it to a byte array.
          string postData = "This is a test that posts this string to a Web server.";
          byte[] byteArray = Encoding.UTF8.GetBytes(postData);
          // Set the ContentType property of the WebRequest.
          request.ContentType = "application/x-www-form-urlencoded";
          // Set the ContentLength property of the WebRequest.
          request.ContentLength = byteArray.Length;
          // Get the request stream.
          Stream dataStream = request.GetRequestStream();
          // Write the data to the request stream.
          dataStream.Write(byteArray, 0, byteArray.Length);
          // Close the Stream object.
          dataStream.Close();
          // Get the response.
          WebResponse response = request.GetResponse();
          // Display the status.
          Console.WriteLine(((HttpWebResponse)response).StatusDescription);
          // Get the stream containing content returned by the server.
          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);
          // Clean up the streams.
          reader.Close();
          dataStream.Close();
          response.Close();
      }

Zkusil jsem: Vytvoriť triedu SendData a skopirovat kód ktorý je hore. A následne vytvoriť instanciu triedy. Send data.
SendData sendData = new SendData();
ale celý kód ktorý je v clase sendData mi stale počiarkuje. Neviem kde je chyba lebo v OOP programovani som zacitocnik.

Chci docílit: Aby daný kod ,ktorý je hore aby bol v triede a tu triedu som si zavolal v main.

Odpovědět
26.6.2019 11:31
"Whether you think you can, or you think you can't - you're right."(Henry Ford)
Avatar
plelovsky
Člen
Avatar
plelovsky:26.6.2019 11:57

Asi nemáš zpřístupněné potřebné namespace:

using System.IO;
using System.Net;
 
Nahoru Odpovědět
26.6.2019 11:57
Avatar
madewman
Člen
Avatar
Odpovídá na plelovsky
madewman:26.6.2019 12:28

No takto to vyzerá zdrojový kod. V prílohe je.

Nahoru Odpovědět
26.6.2019 12:28
"Whether you think you can, or you think you can't - you're right."(Henry Ford)
Avatar
Odpovídá na madewman
Michal Štěpánek:26.6.2019 12:49

A když najedeš myší na to podtržené, co ti ukáže za chybu?

Nahoru Odpovědět
26.6.2019 12:49
Nikdy neříkej nahlas, že to nejde. Vždycky se totiž najde blbec, který to neví a udělá to...
Avatar
Shade
Člen
Avatar
Shade:26.6.2019 14:43

Ten kód nemáš v žádné metodě (nebo konstruktoru) a Main máš o závorku navíc

Editováno 26.6.2019 14:45
Nahoru Odpovědět
26.6.2019 14:43
Talk is cheap. Show me the code.
Avatar
Marek Uhlik
Člen
Avatar
Odpovídá na madewman
Marek Uhlik:26.6.2019 14:45

Neměla by tam být např nějaká metoda Send() {} či něco jiného?
Prostě vytvoř si nějakou metodu a ten kód vlož do ní.

 
Nahoru Odpovědět
26.6.2019 14:45
Avatar
Michal Rýzler
Brigádník
Avatar
Michal Rýzler:27.6.2019 23:05

Musíš si v třídě “SendData” udělat metodu - c.j. Pod “class SendData {“ si napiš “public void SendData() {“,
Poté tam vlož svůj kód a uzavři ho zase “}”

Nahoru Odpovědět
27.6.2019 23:05
Programátor může být každý. Kvalitním programátorem se však už každý nestane.
Avatar
madewman
Člen
Avatar
Odpovídá na Michal Rýzler
madewman:27.6.2019 23:56

Ďakujem pomohlo to.

Nahoru Odpovědět
27.6.2019 23:56
"Whether you think you can, or you think you can't - you're right."(Henry Ford)
Děláme co je v našich silách, aby byly zdejší diskuze co nejkvalitnější. Proto do nich také mohou přispívat pouze registrovaní členové. Pro zapojení do diskuze se přihlas. Pokud ještě nemáš účet, zaregistruj se, je to zdarma.

Zobrazeno 8 zpráv z 8.