Page 1 of 1

HttpRequest multiPart/form-data

Posted: Mon Dec 09, 2024 2:27 pm
by tatanas
Hi,

I'm trying to connect to an Aruba 6300 switch using the REST API. It works fine with this CURL command :

Code: Select all

curl -k -X POST -c c:\auth_cookie -H "Content-Type: multipart/form-data" "https://192.168.1.254/rest/v10.11/login" -F "username=admin" -F "password=123456"
It also works with this PowerShell command :

Code: Select all

Invoke-RestMethod "https://192.168.1.254/rest/v10.11/login" -SkipCertificateCheck -Method Post -Body @{username = "admin"; password = "123456"}
but I'm having trouble with it in PureBasic using HttpRequest(#PB_HTTP_Post, ...). I'm able to connect to other Aruba switch models this way (using the data$ parameter to pass the ID and password in JSON format).

Here is the doc : https://www.arubanetworks.com/techdocs/ ... v10-0x.pdf

Could you help me?

Thanks for you time

Re: HttpRequest multiPart/form-data

Posted: Mon Dec 09, 2024 8:25 pm
by infratec
Try this:

Code: Select all

Post$ = "username=" + URLEncoder("admin")
Post$ + "&"
Post$ + "password=" + URLEncoder("123456")
HTTPRequest = HTTPRequest(#PB_HTTP_Post, "https://192.168.1.254/rest/v10.11/login", Post$, #PB_HTTP_NoSSLCheck)
If HTTPRequest
  Debug HTTPInfo(HTTPRequest, #PB_HTTP_Headers)
  FinishHTTP(HTTPRequest)
EndIf
If the answer is 200 Ok, you need to fiddle out the auth-cookie for further requests.

Re: HttpRequest multiPart/form-data

Posted: Wed Dec 11, 2024 8:47 am
by tatanas
Thank you infratec !
That's the right string to send.