HttpRequest multiPart/form-data

Just starting out? Need help? Post your questions and find answers here.
tatanas
Enthusiast
Enthusiast
Posts: 260
Joined: Wed Nov 06, 2019 10:28 am
Location: France

HttpRequest multiPart/form-data

Post 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
Windows 10 Pro x64
PureBasic 6.20 x64
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: HttpRequest multiPart/form-data

Post 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.
tatanas
Enthusiast
Enthusiast
Posts: 260
Joined: Wed Nov 06, 2019 10:28 am
Location: France

Re: HttpRequest multiPart/form-data

Post by tatanas »

Thank you infratec !
That's the right string to send.
Windows 10 Pro x64
PureBasic 6.20 x64
Post Reply