HTTP - T0pAz - 07.02.2012
Introduction
In this tutorial, I will teach you about HTTP on SA-MP.
What is HTTP?
HTTP is an application protocol for hypermedia information systems. It stands for Hypertext Transfer Protocol.
Why it's needed?
It's needed to permit intermediate network elements to improve or enable communications between clients and servers. With it, you can create the following things:- Radio Station
- E-Mail Sender
How to use it?
It's not really hard to use, but to get started using it, you need to know few things first.
pawn Code:
http
(
index, // ID used to differentiate requests that are sent to the same callback.
type, // The request type.
url[], // The request URL. (Without 'http://')
data[], // Any POST data you want to send with the request.
callback[] // Name of the callback function you want to use to handle responses to this request.
// Returns 1(true) on Success and 0(false) on Failure
)
Request Type | Method |
HEAD | Asks for the response identical to the one that would correspond to a GET request, but without the response body. This is useful for retrieving meta-information written in response headers, without having to transport the entire content. |
GET | Requests a representation of the specified resource. Requests using GET should only retrieve data and should have no other effect. |
POST | Submits data to be processed to the identified resource. The data is included in the body of the request. This may result in the creation of a new resource or the updates of existing resources or both. |
Response Codes | ID |
HTTP_ERROR_BAD_HOST | 1 |
HTTP_ERROR_NO_SOCKET | 2 |
HTTP_ERROR_CANT_CONNECT | 3 |
HTTP_ERROR_CANT_WRITE | 4 |
HTTP_ERROR_CONTENT_TOO_BIG | 5 |
HTTP_ERROR_MALFORMED_RESPONSE | 6 |
Let me now explain in details in every parameters(arguments). The index is used to differentiate the requests that are sent to the same callback which you can use for player. The type as mentioned before is the request type you want to send. The URL is the url you want to request to get data. The data is used for POST to send request with. And last but not least, the callback which is used to get responses to the request. The response code 200 means that the request succeed. There is also and example script on SA-MP WIKI on
HTTP. If you have any question please let me know by posting below.
Note: This thread will be updated frequently depending on the criticism and questions.
Re: HTTP -
MA_proking - 07.02.2012
Nice and help ful tutorial , thanks for it.
Re: HTTP -
2KY - 07.02.2012
This tutorial is useful, but perhaps you could supply more examples than just redirecting us to the SA:MP wiki.
What I'd personally like to see is fetching the text from a file from a website (yoursite.com/motd.txt), and formatting it into a string being able to be sent to the client.
EG: OnPlayerConnect -> use the data collected from the website -> "Server MOTD: %s"
Re: HTTP - T0pAz - 07.02.2012
Quote:
Originally Posted by 2KY
This tutorial is useful, but perhaps you could supply more examples than just redirecting us to the SA:MP wiki.
|
Sure.
Re: HTTP -
2KY - 07.02.2012
Quote:
Originally Posted by T0pAz
Sure.
|
I have edited my post a bit, but I would like to take this opportunity to tell you welcome back.
Oh, and is it possible to store multiple amounts of "queries" in one data response?
E.G: grabbing two different values from one website (yoursite.com/meow.txt) & (yourside.com/woof.txt) and once again, formatting them into one message? I'd assume they'd store like normal 'strings' (i can't think of a better word), but I'm not positive.
Re: HTTP -
Ballu Miaa - 07.02.2012
Can you tell me what is the usage with SA-MP T0pAz?
Re: HTTP - T0pAz - 07.02.2012
@2KY - I will explain it soon but in the meantime, you can try messing up with it.
@Ballu Miaa - It's needed to permit intermediate network elements to improve or enable communications between clients and servers. Useful for web based things like RSS Feeds, E-Mail, etc.
Re: HTTP -
Ballu Miaa - 07.02.2012
Quote:
Originally Posted by T0pAz
@2KY - I will explain it soon but in the meantime, you can try messing up with it.
@Ballu Miaa - It's needed to permit intermediate network elements to improve or enable communications between clients and servers. Useful for web based things like RSS Feeds, E-Mail, etc.
|
So that means i can use this to send emails to users from InGame?
Re: HTTP - T0pAz - 07.02.2012
Quote:
Originally Posted by Ballu Miaa
So that means i can use this to send emails to users from InGame?
|
Correct.
Re: HTTP -
Ballu Miaa - 07.02.2012
Quote:
Originally Posted by T0pAz
Correct.
|
Wow thats fucking amazing? Can you give me an example how can i do it? Can it be a Command for admins? or what? How should i use it?