Thanks to INFRATEC and several members of this forum, i believe i have a little bit understand how use CURL
I have try to send a GET request without success, CURL not see the parameter send
For ask at PB forum to search "KCC", i want send that :
But the result is the full search panel of PB, not the list of thread of KCC
If someone see where is the problem
Code: Select all
; Based on INFRATEC code ReceiveHTTPToMemory() http://www.purebasic.fr/english/viewtopic.php?p=490891#p490891
IncludeFile "libcurl.pbi" ; https://github.com/deseven/pbsamples/tree/master/crossplatform/libcurl
Global *ReceiveHTTPToMemoryBuffer, ReceiveHTTPToMemoryBufferPtr.i
#Requette_GET = 0
#Requette_POST = 1
ProcedureC ReceiveHTTPWriteToMemoryFunction(*ptr, Size.i, NMemB.i, *Stream)
 
 Protected SizeProper.i  = Size & 255
 Protected NMemBProper.i = NMemB
 
 If *ReceiveHTTPToMemoryBuffer = 0
  *ReceiveHTTPToMemoryBuffer = AllocateMemory(SizeProper * NMemBProper)
 Else
  *ReceiveHTTPToMemoryBuffer = ReAllocateMemory(*ReceiveHTTPToMemoryBuffer, MemorySize(*ReceiveHTTPToMemoryBuffer) + SizeProper * NMemBProper)
 EndIf
 
 CopyMemory(*ptr, *ReceiveHTTPToMemoryBuffer + ReceiveHTTPToMemoryBufferPtr, SizeProper * NMemBProper)
 ReceiveHTTPToMemoryBufferPtr + SizeProper * NMemBProper
 
 ProcedureReturn SizeProper * NMemBProper
 
EndProcedure
Procedure.i RequetteHTTP(Adresse.s, Parametre.s = "", Methode = #Requette_GET, Proxy$="", Entete = #False, Delai = 3)
 
 Protected *Buffer
 
 If Len(Adresse)
  
  curl  = curl_easy_init()
  
  If curl
      
   curl_easy_setopt(curl, #CURLOPT_URL, str2curl(Adresse))
   curl_easy_setopt(curl,#CURLOPT_POST, Methode)  ;'POST' request = 1 // 'GET' request = 0
   curl_easy_setopt(curl, #CURLOPT_USERAGENT, "User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:43.0) Gecko/20100101 Firefox/43.0")
   curl_easy_setopt(curl,#CURLOPT_POSTFIELDS, str2curl(Parametre))
   curl_easy_setopt(curl, #CURLOPT_TIMEOUT, Delai)
   
   If Entete
    curl_easy_setopt(curl, #CURLOPT_HEADER, @"")      
   EndIf 
   
   If Len(Proxy$)
    curl_easy_setopt(curl, #CURLOPT_PROXY, str2curl(proxy$))
   EndIf
   
   curl_easy_setopt(curl, #CURLOPT_WRITEFUNCTION, @ReceiveHTTPWriteToMemoryFunction())
   res = curl_easy_perform(curl)
   
   If res = #CURLE_OK
   
    *Buffer = AllocateMemory(ReceiveHTTPToMemoryBufferPtr)
    
    If *Buffer
     CopyMemory(*ReceiveHTTPToMemoryBuffer, *Buffer, ReceiveHTTPToMemoryBufferPtr)
     FreeMemory(*ReceiveHTTPToMemoryBuffer)
     *ReceiveHTTPToMemoryBuffer = #Null
     ReceiveHTTPToMemoryBufferPtr = 0
    EndIf
    
   EndIf
   
   curl_easy_cleanup(curl)
   
  EndIf
  
 EndIf 
 
 ProcedureReturn *Buffer
 
EndProcedure
CompilerIf #PB_Compiler_IsMainFile
 
 Define *Buffer, Proxy$
 InitNetwork()
  
 Proxy$ = "http://xxxxxx.xxx.fr:3128"
 
 *Buffer = RequetteHTTP("http://www.purebasic.fr/english/search.php", "keywords=kcc&terms=all&author=&sc=1&sf=all&sk=t&sd=d&sr=topics&st=0&ch=300&t=0&submit=Search", #Requette_GET, Proxy$, #False,10)
 
 If *Buffer
  Debug PeekS(*Buffer, MemorySize(*Buffer), #PB_UTF8|#PB_ByteLength)
  FreeMemory(*Buffer)
 EndIf
 ;  
CompilerEndIf



