HttpRequest POST simple not works

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

HttpRequest POST simple not works

Post 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
Last edited by Kwai chang caine on Sun Oct 04, 2020 8:12 pm, edited 1 time in total.
ImageThe happiness is a road...
Not a destination
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: HttpRequest POST

Post 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?
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: HttpRequest POST

Post 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)
ImageThe happiness is a road...
Not a destination
User avatar
NicTheQuick
Addict
Addict
Posts: 1224
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: HttpRequest POST simple not works [Resolved]

Post 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.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
Fred
Administrator
Administrator
Posts: 16619
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: HttpRequest POST simple not works [Resolved]

Post by Fred »

I agree
Post Reply