Page 1 of 1

HttpRequest POST simple not works

Posted: Sun Oct 04, 2020 7:34 pm
by Kwai chang caine
Hello at all

I have not really understand the POST method :oops:

I have this php code

Code: Select all

function Ajoute($Texte)
	{
		$Ecriture = fopen("ListeTextes.txt", "a");
		fputs($Ecriture, "\n" . $Texte);
		fclose($Ecriture);
	}
        
if (isset($_POST['Action']) && isset($_POST['Valeur']))
	{
		$Action = $_POST['Action'];
		$Valeur = $_POST['Valeur'];
				
		if ($Action == "Ajoute")
		{
			Ajoute($Valeur);
		}

	}
And when i use this PB code that not works :|

Code: Select all

Url$ = "http://Mysite/index.php"

InitNetwork() 
HttpRequest = HTTPRequest(#PB_HTTP_Post, Url$, "Action=Ajoute&Valeur=hello")

If HttpRequest
 
 Debug "Status: " + HTTPInfo(HTTPRequest, #PB_HTTP_StatusCode)
 Debug "Réponse: " + HTTPInfo(HTTPRequest, #PB_HTTP_Response)
 FinishHTTP(HTTPRequest)
 
Else

 MessageRequester("Erreur", "La requete n'a pas été envoyée")
 
EndIf 
 
Thanks and have a good day

Re: HttpRequest POST

Posted: Sun Oct 04, 2020 7:54 pm
by infratec
Maybe your server needs the Content-Length:

Code: Select all

NewMap Header$()

Url$ = "http://myip/index.php"
Post$ = "Action=Ajoute&Valeur=hello"

Header$("Content-Length") = Str(StringByteLength(Post$, #PB_UTF8))

InitNetwork()
HttpRequest = HTTPRequest(#PB_HTTP_Post, Url$, Post$, 0, Header$())

If HttpRequest
  
  Debug "Status: " + HTTPInfo(HTTPRequest, #PB_HTTP_StatusCode)
  Debug "Réponse: " + HTTPInfo(HTTPRequest, #PB_HTTP_Response)
  FinishHTTP(HTTPRequest)
  
Else
  
  MessageRequester("Erreur", "La requete n'a pas été envoyée")
  
EndIf 
Or is there a Cookie required?

Re: HttpRequest POST

Posted: Sun Oct 04, 2020 8:12 pm
by Kwai chang caine
Decidedly you are the king of HTTP :shock:
That works now , thanks a lot INFRATEC and have a good night 8)

Re: HttpRequest POST simple not works [Resolved]

Posted: Mon Oct 05, 2020 10:02 am
by NicTheQuick
Hm, this would be a nice feature request. In general it makes no sense to set Post data but write no Content-Length header. It is useful for streaming data but in this case HTTPRequest always sends a predefined request with a defined length. it would be nice if the Content-Length would be set automatically.

Re: HttpRequest POST simple not works [Resolved]

Posted: Mon Oct 05, 2020 1:33 pm
by Fred
I agree