[Tutorial] HTTP
#1

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.
Reply


Messages In This Thread
HTTP - by T0pAz - 07.02.2012, 07:38
Re: HTTP - by MA_proking - 07.02.2012, 07:41
Re: HTTP - by 2KY - 07.02.2012, 14:24
Re: HTTP - by T0pAz - 07.02.2012, 14:25
Re: HTTP - by 2KY - 07.02.2012, 14:30
Re: HTTP - by Ballu Miaa - 07.02.2012, 14:30
Re: HTTP - by T0pAz - 07.02.2012, 14:35
Re: HTTP - by Ballu Miaa - 07.02.2012, 15:07
Re: HTTP - by T0pAz - 07.02.2012, 15:10
Re: HTTP - by Ballu Miaa - 07.02.2012, 15:12

Forum Jump:


Users browsing this thread: 1 Guest(s)