SA-MP Forums Archive
[Tutorial] HTTP - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] HTTP (/showthread.php?tid=316484)



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 TypeMethod
HEADAsks 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.
GETRequests a representation of the specified resource. Requests using GET should only retrieve data and should have no other effect.
POSTSubmits 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 CodesID
HTTP_ERROR_BAD_HOST1
HTTP_ERROR_NO_SOCKET2
HTTP_ERROR_CANT_CONNECT3
HTTP_ERROR_CANT_WRITE4
HTTP_ERROR_CONTENT_TOO_BIG5
HTTP_ERROR_MALFORMED_RESPONSE6






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
View Post
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
View Post
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
View Post
@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
View Post
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
View Post
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?