PureBasic
PureBasic
Transition from Http.PostJson2 to Http.HttpStr
Provides instructions for replacing deprecated PostJson2 method calls with HttpStr.Chilkat PureBasic Downloads
IncludeFile "CkHttpResponse.pb"
IncludeFile "CkHttp.pb"
Procedure ChilkatExample()
success.i = 0
http.i = CkHttp::ckCreate()
If http.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
url.s = "https://example.com/something"
contentType.s = "application/json"
jsonText.s = "{ ... }"
; ------------------------------------------------------------------------
; The PostJson2 method is deprecated:
responseObj.i = CkHttp::ckPostJson2(http,url,contentType,jsonText)
If CkHttp::ckLastMethodSuccess(http) = 0
Debug CkHttp::ckLastErrorText(http)
CkHttp::ckDispose(http)
ProcedureReturn
EndIf
; ...
; ...
CkHttpResponse::ckDispose(responseObj)
; ------------------------------------------------------------------------
; Do the equivalent using HttpStr.
; Your application creates a new, empty HttpResponse object which is passed
; in the last argument and filled upon success.
responseOut.i = CkHttpResponse::ckCreate()
If responseOut.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkHttp::ckHttpStr(http,"POST",url,jsonText,"utf-8",contentType,responseOut)
If success = 0
Debug CkHttp::ckLastErrorText(http)
CkHttp::ckDispose(http)
CkHttpResponse::ckDispose(responseOut)
ProcedureReturn
EndIf
CkHttp::ckDispose(http)
CkHttpResponse::ckDispose(responseOut)
ProcedureReturn
EndProcedure