Jump to content

Curl UDF - libcurl with x64 support


Beege
 Share

Recommended Posts

20 minutes ago, Mamrot said:

First of all, thank you for the great UDF.
I don't know if it's my mistake, lack of knowledge or a bug.
I'm trying to send simple JSON data using the PUT method, when I use PostMan desktop app to do so, everything works fine.
When I try this from code I get a problem.

#include <Date.au3>
#include <WinAPIDiag.au3>
#include "Curl.au3"

Test()

Func Test()

    ;Create an array of request headers
    $aHeaders = Curl_Slist_Append(0, "X-API-KEY: ZXBwbGlE3bnpJdEFtYitHUTY=")
    $aHeaders = Curl_Slist_Append($aHeaders, "Content-Type: application/json")

    ;Set up and execute cURL request
    $hCurl = Curl_Easy_Init()
    If Not $hCurl Then Return MsgBox($MB_ICONERROR, "Error", "Curl_Easy_Init() failed.")

    Curl_Easy_Setopt($hCurl, $CURLOPT_URL, "https://postman-echo.com/put")
;~  Curl_Easy_Setopt($hCurl, $CURLOPT_URL, "https://jsonplaceholder.typicode.com/puts")
    Curl_Easy_Setopt($hCurl, $CURLOPT_HTTPHEADER, $aHeaders)
    Curl_Easy_Setopt($hCurl, $CURLOPT_USERAGENT, "AutoIt/cURL")
    Curl_Easy_Setopt($hCurl, $CURLOPT_VERBOSE, 1)
    Curl_Easy_Setopt($hCurl, $CURLOPT_SSL_VERIFYPEER, 0)
    Curl_Easy_Setopt($hCurl, $CURLOPT_READFUNCTION, Curl_DataReadCallback())
    Curl_Easy_Setopt($hCurl, $CURLOPT_CUSTOMREQUEST, "PUT")
    Curl_Easy_Setopt($hCurl, $CURLOPT_UPLOAD, 1)
    Curl_Easy_Setopt($hCurl, $CURLOPT_POSTFIELDS, '{"params":{"settings":{"settingModificationType":"edit"},"products":[{"productId":51,"productRetailPrice":48,"productVat":23}]}}')

    ;Get response code and response
    $iRespCode = Curl_Easy_Perform($hCurl)
    If $iRespCode <> $CURLE_OK Then Return ConsoleWrite("Status Message: " & Curl_Easy_StrError($iRespCode) & @LF)
    $sResponse = BinaryToString(Curl_Data_Get($hCurl))

    ;Clean up curl environment
    Curl_Easy_Cleanup($hCurl)
    Curl_Data_Cleanup($hCurl)

    ;Display response
    ConsoleWrite($sResponse & @CRLF)
EndFunc   ;==>Test

PostMan-Echo returns :

{
  "args": {},
  "data": "����",
  "files": {},
  "form": {},
  "headers": {
    "x-forwarded-proto": "https",
    "x-forwarded-port": "443",
    "host": "postman-echo.com",
    "x-amzn-trace-id": "Root=1-65c98445-0b5caa1f68b222370524152d",
    "content-length": "4",
    "user-agent": "AutoIt/cURL",
    "accept": "*/*",
    "x-api-key": "ZXBwbGlE3bnpJdEFtYitHUTY=",
    "content-type": "application/json",
    "accept-encoding": "gzip, deflate, br"
  },
  "json": null,
  "url": "https://postman-echo.com/put"

Why does "data": "����" contain such characters instead of my JSON data?

Any help is greatly appreciated.

 

Regards, M.

Try using copy post field instead of post field

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...