Jump to content

Ad Block detected  

Welcome To The Home Of
AspectModding

Extra discount

  • Chaotic360 sales are now on
  • 20$ For lifetime premium 
  • Limited time only

AspectModding is currently under maintenance if you discover any bugs and/or errors report them to a member of staff  right away!

To become a beta tester of Chaotic360 Remastered V3.0.0 Message ZZ9 x iHaXoRZz or ZZ9 x iCalZz

distancexd

Member
  • Content count

    3
  • Joined

  • Last visited

Everything posted by distancexd

  1. yO

    im chris i code stuff. cya
  2. [c#] Extensions

    What are extensions? An extension method enables you to add methods to existing types without creating a new derived type, recompiling, or modify the original types. We can say that it extends the functionality of an existing type in .NET. An extension method is a static method to the existing static class. We call an extension method in the same general way; there is no difference in calling. The following list contains basic features and properties of extension methods It is a static method. It must be located in a static class. It uses the "this" keyword as the first parameter with a type in .NET and this method will be called by a given type instance on the client side. It also shown by VS intellisense. When we press the dot (.) after a type instance, then it comes in VS intellisense. An extension method should be in the same namespace as it is used or you need to import the namespace of the class by a using statement. You can give any name for the class that has an extension method but the class should be static. If you want to add new methods to a type and you don't have the source code for it, then the solution is to use and implement extension methods of that type. If you create extension methods that have the same signature methods as the type you are extending, then the extension methods will never be called. How do I create an extension in c#? public static class MyExtension { public static void MyMethod(this <type> <name>, <extra objects>) { } } __________________________________________________ Example public static int CountVowels(this string str) { char[] vowels = new char[] { 'a', 'e', 'i', 'o', 'u' }; int vowelCount = 0; for (int i = 0; i < str.Length; i++) { char current = str[i]; if (vowels.Any(x => current == x)) { vowelCount = vowelCount + 1; } return vowelCount; } } Usage int vowels = "some random string".CountVowels(); __________________________________________________ Example w/ additional input. public static bool EqualsIgnoreCase(this string str, string equals) { return str.ToLower() == equals.ToLower(); } Usage bool equals = "RANDOM STRING".EqualsIgnoreCase("RaNdOm StRiNg"); __________________________________________________ ~the descriptions were not written by me but the code examples were.
  3. [c#] HttpWebRequest

    What is an HttpWebRequest? Whenever your web browser fetches a file (a page, a picture, etc) from a web server, it does so using HTTP - that's "Hypertext Transfer Protocol". HTTP is a request/response protocol, which means your computer sends a request for some file (e.g. "Get me the file 'home.html'"), and the web server sends back a response ("Here's the file", followed by the file itself). Request Methods POST GET HEAD PUT DELETE OPTIONS CONNECT I will be showing you how to use all the request methods inside of c#. But first we need to learn the basics. First. we need to create a new HttpWebRequest object. HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.site.com/login.php"); Next. We need to set the request method, this method can be any of the methods listed above. Note: if you set it to "POST" make sure you also write post data to the request. request.Method = "POST" Headers Headers are a bit weird because there are 2 ways to set them: request.HeaderName = "HeaderValue"; request.Headers.Add("HeaderName", "HeaderValue"); request.HeaderName = "HeaderValue"; Corresponds to the following headers: Accept Connection Content-Type Date Expect Host Content-Length Referer TE User-Agent Method request.Headers.Add("HeaderName", "HeaderValue"); Corresponds to any headers not specified above. Writing Post Data Writing post data is needed to write data to the WebRequest whenever the request method is "POST". Note: this is not required with request method other than POST string data = "username=username&password=password"; byte[] dataBytes = Encoding.ASCII.GetBytes(data); request.ContentLength = dataBytes.Length; using (Stream stream = request.GetRequestStream()) { stream.Write(dataBytes, 0, dataBytes.Length); stream.Close(); } Getting the Response Once you are done writing post data, or setting the headers you need to send the request to the specified url and get the response back. HttpWebResponse response = (HttpWebResponse)request.GetResponse(); string responseString = string.Empty; using (StreamReader reader = new StreamReader(response.GetResponseStream())) { responseString = reader.ReadToEnd(); } ....... Now that you know the basics of creating a WebRequest. As an example I will send a POST, and GET request to 2 websites. (documentation added) This is the WebRequest you send. I will be breaking it down and converting it into c# code. GET http://aspectmodding.net/ HTTP/1.1 Host: aspectmodding.net Connection: keep-alive Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 Referer: http://aspectmodding.net/ Accept-Encoding: gzip, deflate, sdch Accept-Language: en-US,en;q=0.8 Cookie: __cfduid=d9979f163fff28268c362489963d14a701498168864; ips4_IPSSessionFront=p4837m5chs9b5qa6ls4vnpb4q5; ips4_ipsTimezone=America/Tijuana; ips4_hasJS=true GET http://aspectmodding.net/ HTTP/1.1 This line is pretty simple. It contains the Method, Url and HTTP Version. Request Method: GET Request URL: http://aspectmodding.net/ HTTP Version: HTTP/1.1 > c# HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://aspectmodding.net/"); request.Method = "GET"; --------------- Host: aspectmodding.net Connection: keep-alive Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 Referer: http://aspectmodding.net/ Accept-Encoding: gzip, deflate, sdch Accept-Language: en-US,en;q=0.8 Cookie: __cfduid=d9979f163fff28268c362489963d14a701498168864; ips4_IPSSessionFront=p4837m5chs9b5qa6ls4vnpb4q5; ips4_ipsTimezone=America/Tijuana; ips4_hasJS=true These lines are all the headers. > c# request.Host = "aspectmodding.net"; request.KeepAlive = true; request.Headers.Add("Upgrade-Insecure-Requests", "1"); request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"; request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"; request.Referer = "http://aspectmodding.net/"; request.Headers.Add("Accept-Language", "en-US,en;q=0.8"); request.Headers.Add("Cookie", "__cfduid=d9979f163fff28268c362489963d14a701498168864; ips4_IPSSessionFront=p4837m5chs9b5qa6ls4vnpb4q5; ips4_ipsTimezone=America/Tijuana; ips4_hasJS=true"); --- And for the response > c# HttpWebResponse response = (HttpWebResponse)request.GetResponse(); string responseString = string.Empty; using (StreamReader reader = new StreamReader(response.GetResponseStream())) { responseString = reader.ReadToEnd(); } -- Response

About us

Welcome to the home of AspectModding where we offer
you your daily mods to your general gossip, if your into
gaming, modding, programming, or just looking for new
friends this is the place for you

Follow us

×