Login Register






There was a very particular style of DDOS attack just now, it was mitigated.
Thread Rating:
  • 0 Vote(s) - 0 Average


Tutorial Link Shortener / API Based Result Handling filter_list
Author
Message
Link Shortener / API Based Result Handling #1
API Based Results Tutorial

Summary
In this tutorial, I hope to help you better understand web client usage, API response handling, and general API usage. API's are very helpful for sending short, quick requests and having a server handle most of the work for you, while also making it easier on a programmer to do their job. We're going to start off with creating the new program, designing the UI, then sending the request while looking at some extra options for the webclient, and finally parsing the result. Shortly after this tutorial is posted, I will post an API creation tutorial in the PHP/"Web" section. We are going to be using my API to shorten URLs in this tutorial.

API
Application programming interface

Uses
  • Simpler Website Requests
  • Faster Programming
  • Less computer usage
  • EASIER!

Required Materials
  • Microsoft Visual Studio ( I am using 2012 Pro )
  • A basic understanding of .Net software development
  • Internet Connection
  • Common Sense


Alright, now that I passed along that (mostly) useless information, let's get started!

Step 1: A New Project
Firstly, you will need to make a new Visual Basic Windows Forms Application. You can name it anything you like, it does not affect the project.

Spoiler:
[Image: 3Bv9D.png]

Step 2: GUI Design
Now we need to build the GUI. You will need the following controls:
  • (2) Text Boxes
  • (2) Labels
  • (1) Button

Lay them out any way you wish, but this is how I laid mine out:

Spoiler:
[Image: 3Bvkv.png]


Now, let's do some renaming and re-texting. Change the first label to: "Input" and the second label to "Result". Change the form title to whatever you like. Change the button text to "Shorten".

Alright, now we have to RENAME the two text boxes and the button. Click on the first text box and find the name property on the "Properties" tab:

[Image: 3BvwL.png]

Rename the first text box to: txtInput
Rename the second text box to: txtResult
Rename the button to: btnShorten

*computer just crashed, so I had to remake my project Sad*

Alright, now that the controls are renamed, on to the coding!

Step 3: Coding
Now we learn how to actually interact with the API using a web client!

Double click the button, and you should be brought to the code editor which should look exactly like this:

Spoiler:
[Image: 3Bw8N.png]

Before we can use any web clients, we first need to import System.Net. So go to line one and free up a few lines and type:

Code:
Imports System.Net

You code page should now look like this:

Spoiler:
[Image: 3BweB.png]

Now we are able to use web clients in our project. In order to do that, we must first declare a new web client. But before doing that, let's check if the user put anything into the input text box before doing unnecessary work. Put the following code into the sub:

Code:
If txtInput.Text = Nothing Then

MessageBox.Show("Please enter a URL into the input box!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

End If

That will make sure that the user of the program actually put in a URL to be shortened.

After that code, let's declare the WebClient.

Code:
Dim Shorten as New WebClient

Now, if you wanted to do some basic protection from Fiddler if this was a sensitive request, you could do:

Code:
Shorten.Proxy = Nothing

You can also assign custom user agents for your WebClients as well. But moving on. We want to have some basic error handling in case anything goes wrong, so let's put in a "Try" statement in case anything goes wrong:

Code:
Try

Catch ex As Exception

            MessageBox.Show(ex.ToString, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

End Try

Notice how I put in the message box explaining that an error occurred, along with displaying the actual error as the text of the message box. Now, to actually use the WebClient we use the following code:

Code:
txtResult.Text = Shorten.DownloadString("http://my-x-api.tk/us/short.php?url=" & txtInput.Text)

We are feeding the results of the request directly into the text box for ease of use. Shorten is the name of the WebClient, the
Quote:http://my-x-api.tk/us/short.php
is my API ( that I coded for shortening URLs ) that we are calling with the WebClient, and the

Code:
& txtInput.Text
is us putting in the URL that the user entered into the input box.

Now, your code should look like this:

Spoiler:
[Image: 3BwMD.png]

Congratulations, you have just finished a working URL shortener! Just press F5 to debug and test it and you are good to go! Thank you for reading this tutorial and I hope you enjoy it. Please leave constructive criticism!
Selling ownership of Agony Products and InfernoAPI, PM me for details or to make an offer!

Reply

RE: Link Shortener / API Based Result Handling #2
Nice, and detailed tutorial! Liking it buddy!
[Image: GiXvY27.png]

Reply

RE: Link Shortener / API Based Result Handling #3
Very nice tut, and it has some good uses other than the link shortener. I might use this for a private booter myself.

Reply

RE: Link Shortener / API Based Result Handling #4
This is actually a nice tutorial, thanks man.

Reply







Users browsing this thread: 1 Guest(s)






This forum uses Lukasz Tkacz MyBB addons.