PB:
Code: Select all
Procedure SendResponse(clientID.i, response.s, status.s, keep_alive.b = #False)
If keep_alive
connection.s = "keep-alive"
Else
connection.s = "close"
EndIf
template.s = ~"HTTP/1.1 " + status +
~"\r\nAccess-Control-Allow-Origin: *" + ; Private APIs should not allow all origins, but only its domain.
~"\r\nConnection: " + connection +
~"\r\nContent-Length: " + StringByteLength(response, #PB_UTF8) +
~"\r\nContent-Type: text/html; charset=utf-8" +
~"\r\nServer: PureBasic" +
~"\r\nDate: " + FormatDate("%dd/%mm/%yyyy", Date()) +
~"\r\n\r\n" + response
; See https://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html.
SendNetworkString(clientID, template)
EndProcedure
Code: Select all
Procedure HttpGet(success, result.s, userData)
If success
Debug result ; SendNetworkString() on server.
Else
Debug "HTTPRequest(): Error"
EndIf
EndProcedure
HTTPRequest(#PB_HTTP_Get, "http://localhost:6832/get", "name1=value1&name2=value2", @HttpGet())
HTTPRequest(#PB_HTTP_Post, "http://localhost:6832/post", "PostParam", @HttpGet())
HTTPRequest(#PB_HTTP_Put, "http://localhost:6832/put", "PutParam", @HttpGet())
HTTPRequest(#PB_HTTP_Delete, "http://localhost:6832/delete", "DelParam", @HttpGet())
1. PUT and DELETE both return an error (Debug "HTTPRequest(): Error").
2. Both have an OPTIONS method in the header. I don’t understand why the header does not respect the same standards as GET (GET /get) and POST (POST /post) methods.
3. The server does not receive the parameter. ie. it’s not in the header.
Header received with the PUT method:
Code: Select all
OPTIONS /put HTTP/1.1
Host: localhost:6832
Connection: keep-alive
Accept: */*
Access-Control-Request-Method: PUT
Origin: http://127.0.0.1:9080
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36
Sec-Fetch-Mode: cors
Sec-Fetch-Site: cross-site
Sec-Fetch-Dest: empty
Referer: http://127.0.0.1:9080/
Accept-Encoding: gzip, deflate, br
Accept-Language: fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7,en-GB;q=0.6