Werty Posted February 12 Share Posted February 12 You posted your API key, dont know if that's a good idea. Some guy's script + some other guy's script = my script! Link to comment Share on other sites More sharing options...
n3wbie Posted February 12 Share Posted February 12 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. expandcollapse popup#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 Mamrot 1 Link to comment Share on other sites More sharing options...
Mamrot Posted February 12 Share Posted February 12 4 hours ago, Werty said: You posted your API key, dont know if that's a good idea. The API key is not real, that's not what's causing the problems, but thank you for your attention. Link to comment Share on other sites More sharing options...
Mamrot Posted February 12 Share Posted February 12 4 hours ago, n3wbie said: Try using copy post field instead of post field It helped, thank you very much for the accurate tip. Best regards, M. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now