OUR BLOG

Company News and Updates

Every week we share out expertise on effective strategies and technics to help you reach customers and prospects across the entire web.

Chapter97:FileandStreamI/O

Parameter                                                                Details path                The locationof thefile. append           Ifthefileexist,truewilladddatatotheendofthefile(append),falsewilloverwritethefile. text Text to be written or stored. contents        A collection of strings to be written. source            The location of the file you want to use. dest       The location you want…
Continue Reading

Chapter98:Networking

Section98.1:BasicTCPCommunicationClient ThiscodeexamplecreatesaTCPclient,sends"HelloWorld"overthesocketconnection,andthenwritestheserver response to the console before closing the connection. //DeclareVariables stringhost="stackoverflow.com"; intport=9999; inttimeout=5000; //CreateTCPclientandconnect using(var_client=newTcpClient(host,port)) using(var_netStream=_client.GetStream()) { _netStream.ReadTimeout=timeout; //Writeamessageoverthesocket stringmessage="HelloWorld!"; byte[]dataToSend=System.Text.Encoding.ASCII.GetBytes(message); _netStream.Write(dataToSend,0,dataToSend.Length); //Readserverresponse byte[]recvData=newbyte[256]; intbytes=_netStream.Read(recvData,0,recvData.Length); message=System.Text.Encoding.ASCII.GetString(recvData,0,bytes); Console.WriteLine(string.Format("Server: {0}",message)); };//Theclientandstreamwillcloseascontrolexitstheusingblock(Equivilentbutsaferthan callingClose(); Section98.2: Download a file froma web server…
Continue Reading

Chapter99: PerformingHTTP requests

Section99.1:CreatingandsendinganHTTPPOSTrequest usingSystem.Net; usingSystem.IO; ... stringrequestUrl="https://www.example.com/submit.html"; HttpWebRequestrequest=HttpWebRequest.CreateHttp(requestUrl); request.Method="POST"; //Optionally,setpropertiesoftheHttpWebRequest,suchas:request.AutomaticDecompression=DecompressionMethods.Deflate|DecompressionMethods.GZip; request.ContentType="application/x-www-form-urlencoded"; //CouldalsosetotherHTTPheaderssuchasRequest.UserAgent,Request.Referer, //Request.Accept,orotherheadersviatheRequest.Headerscollection. //SetthePOSTrequestbodydata.Inthisexample,thePOSTdataisin //application/x-www-form-urlencodedformat. stringpostData="myparam1=myvalue1&myparam2=myvalue2"; using(varwriter=newStreamWriter(request.GetRequestStream())) { writer.Write(postData); } //Submittherequest,andgettheresponsebodyfromtheremoteserver. stringresponseFromRemoteServer; using(HttpWebResponseresponse=(HttpWebResponse)request.GetResponse()) { using(StreamReaderreader=newStreamReader(response.GetResponseStream())) { responseFromRemoteServer=reader.ReadToEnd(); } } Section99.2:CreatingandsendinganHTTPGETrequest usingSystem.Net; usingSystem.IO; ... stringrequestUrl="https://www.example.com/page.html"; HttpWebRequestrequest=HttpWebRequest.CreateHttp(requestUrl); //Optionally,setpropertiesoftheHttpWebRequest,suchas:request.AutomaticDecompression=DecompressionMethods.GZip|DecompressionMethods.Deflate; request.Timeout=2*60*1000;//2minutes,inmilliseconds //Submittherequest,andgettheresponsebody. stringresponseBodyFromRemoteServer; using(HttpWebResponseresponse=(HttpWebResponse)request.GetResponse())…
Continue Reading

About this blog

We are a digital marketing company with a focus on helping our customers achieve great results across several key areas.

Request a free quote

We offer professional SEO services that help websites increase their organic search score drastically in order to compete for the highest rankings even when it comes to highly competitive keywords.

Subscribe to our newsletter!