JSON Post and Get sample
- cdmmaui
- Posts: 653
- Joined: Fri Oct 28, 2005 9:53 am
- Location: The Woodlands - Dallas - Scottsdale - London
- Contact:
JSON Post and Get sample
Hello,
Does anyone have a JSON example that includes authentication.
I tried the following but got the error listed below:
//////////////////////////////////////////////////////////////// CODE
#include "FiveWin.ch"
REQUEST DBFCDX
REQUEST DBFFPT
//-----------------------------------------------------------------------------
function Main()
local ohttp := CreateObject( "MSXML2.XMLHTTP" )
local strret
ohttp:Open( "GET" ,"https://www.winwebconnect.com/api/v1/Login", .F. )
ohttp:SetRequestHeader( "Accept" , "application/json" )
ohttp:SetRequestHeader( "Content-Type" , "application/json" )
ohttp:SetRequestHeader( "Username" , "xxx" )
ohttp:SetRequestHeader( "Password" , "xxx" )
strret := alltrim(ohttp:responseText)
MsgInfo( strret )
RETURN 0
//////////////////////////////////////////////////////////////// REPONSE
Application
===========
Path and name: C:\Winapps\cargo\data\winweb.exe (32 bits)
Size: 3,068,928 bytes
Compiler version: Harbour 3.2.0dev (r1306132159)
FiveWin Version: FWH 14.09
Windows version: 6.1, Build 7601 Service Pack 1
Time from start: 0 hours 0 mins 0 secs
Error occurred at: 01/06/17, 14:55:24
Error description: (DOS Error -2147352567) WINOLE/1007 Unspecified error
(0x80004005): msxml3.dll
Stack Calls
===========
Called from: => TOLEAUTO:RESPONSETEXT( 0 )
Called from: winweb.prg => MAIN( 37 )
System
======
CPU type: Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz 2717 Mhz
Hardware memory: 32652 megs
Free System resources: 90 %
GDI resources: 90 %
User resources: 90 %
Windows total applications running: 5
1 ,
2 , C:\Winapps\cargo\data\winweb.exe
Does anyone have a JSON example that includes authentication.
I tried the following but got the error listed below:
//////////////////////////////////////////////////////////////// CODE
#include "FiveWin.ch"
REQUEST DBFCDX
REQUEST DBFFPT
//-----------------------------------------------------------------------------
function Main()
local ohttp := CreateObject( "MSXML2.XMLHTTP" )
local strret
ohttp:Open( "GET" ,"https://www.winwebconnect.com/api/v1/Login", .F. )
ohttp:SetRequestHeader( "Accept" , "application/json" )
ohttp:SetRequestHeader( "Content-Type" , "application/json" )
ohttp:SetRequestHeader( "Username" , "xxx" )
ohttp:SetRequestHeader( "Password" , "xxx" )
strret := alltrim(ohttp:responseText)
MsgInfo( strret )
RETURN 0
//////////////////////////////////////////////////////////////// REPONSE
Application
===========
Path and name: C:\Winapps\cargo\data\winweb.exe (32 bits)
Size: 3,068,928 bytes
Compiler version: Harbour 3.2.0dev (r1306132159)
FiveWin Version: FWH 14.09
Windows version: 6.1, Build 7601 Service Pack 1
Time from start: 0 hours 0 mins 0 secs
Error occurred at: 01/06/17, 14:55:24
Error description: (DOS Error -2147352567) WINOLE/1007 Unspecified error
(0x80004005): msxml3.dll
Stack Calls
===========
Called from: => TOLEAUTO:RESPONSETEXT( 0 )
Called from: winweb.prg => MAIN( 37 )
System
======
CPU type: Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz 2717 Mhz
Hardware memory: 32652 megs
Free System resources: 90 %
GDI resources: 90 %
User resources: 90 %
Windows total applications running: 5
1 ,
2 , C:\Winapps\cargo\data\winweb.exe
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
- cdmmaui
- Posts: 653
- Joined: Fri Oct 28, 2005 9:53 am
- Location: The Woodlands - Dallas - Scottsdale - London
- Contact:
Re: JSON Post and Get sample
Hello,
Thank you. I changed code and got it to run.
Response:
{"Type":"Request","Message":"Invalid username or password.","Code":"401","Params":[]}
I am checking with provider to confirm credentials are valid.
*********************************************************************************************
#include "FiveWin.ch"
REQUEST DBFCDX
REQUEST DBFFPT
//-----------------------------------------------------------------------------
function Main()
LOCAL oHttp, cHttpSend := ""
cHttpSend := [{ "Username": "xxx", "Password": "xxx"}]
oHttp:=CreateObject( "winhttp.winHttpRequest.5.1" )
oHttp:Open("POST","https://www.winwebconnect.com/api/v1/Login",.F.)
oHttp:SetRequestHeader( "Content-Type","application/json")
oHttp:SetRequestHeader( "Accept","application/json")
oHttp:Send( cHttpSend )
oHttp:waitForResponse()
MsgInfo( oHttp:ResponseText() )
RETURN 0
Thank you. I changed code and got it to run.
Response:
{"Type":"Request","Message":"Invalid username or password.","Code":"401","Params":[]}
I am checking with provider to confirm credentials are valid.
*********************************************************************************************
#include "FiveWin.ch"
REQUEST DBFCDX
REQUEST DBFFPT
//-----------------------------------------------------------------------------
function Main()
LOCAL oHttp, cHttpSend := ""
cHttpSend := [{ "Username": "xxx", "Password": "xxx"}]
oHttp:=CreateObject( "winhttp.winHttpRequest.5.1" )
oHttp:Open("POST","https://www.winwebconnect.com/api/v1/Login",.F.)
oHttp:SetRequestHeader( "Content-Type","application/json")
oHttp:SetRequestHeader( "Accept","application/json")
oHttp:Send( cHttpSend )
oHttp:waitForResponse()
MsgInfo( oHttp:ResponseText() )
RETURN 0
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: JSON Post and Get sample
This is not required.cdmmaui wrote: oHttp:waitForResponse()
EMG
- cdmmaui
- Posts: 653
- Joined: Fri Oct 28, 2005 9:53 am
- Location: The Woodlands - Dallas - Scottsdale - London
- Contact:
Re: JSON Post and Get sample
Hello,
Is there anything else I need to change to code below? I am not getting expected result.
******************** CODE ********************
#include "FiveWin.ch"
REQUEST DBFCDX
REQUEST DBFFPT
//-----------------------------------------------------------------------------
function Main()
LOCAL oHttp, cHttpSend := "", oClp, cResp
cHttpSend := [{ "Username": "xxx", "Password": "xxx"}]
oHttp:=CreateObject( "winhttp.winHttpRequest.5.1" )
oHttp:Open("POST","https://www.winwebconnect.com/api/v1/Login",.F.)
oHttp:SetRequestHeader( "Content-Type","application/json")
oHttp:SetRequestHeader( "Accept","application/json")
oHttp:Send( cHttpSend )
cResp := oHttp:ResponseText()
MsgInfo( cResp )
RETURN 0
******************** RESPONSE ********************
{"Type":"Request","Message":"Invalid username or password.","Code":"401","Params":[]}
Is there anything else I need to change to code below? I am not getting expected result.
******************** CODE ********************
#include "FiveWin.ch"
REQUEST DBFCDX
REQUEST DBFFPT
//-----------------------------------------------------------------------------
function Main()
LOCAL oHttp, cHttpSend := "", oClp, cResp
cHttpSend := [{ "Username": "xxx", "Password": "xxx"}]
oHttp:=CreateObject( "winhttp.winHttpRequest.5.1" )
oHttp:Open("POST","https://www.winwebconnect.com/api/v1/Login",.F.)
oHttp:SetRequestHeader( "Content-Type","application/json")
oHttp:SetRequestHeader( "Accept","application/json")
oHttp:Send( cHttpSend )
cResp := oHttp:ResponseText()
MsgInfo( cResp )
RETURN 0
******************** RESPONSE ********************
{"Type":"Request","Message":"Invalid username or password.","Code":"401","Params":[]}
Re: JSON Post and Get sample
Please try,
oHttp:SetRequestHeader( "Authorization",cHttpSend)
Please note that the format of cHttpSend depends on the format expected by your API provider. I assume that you have clear idea about it and you have filled the contents of cHttpSend accordingly
Regards
Anser
oHttp:SetRequestHeader( "Authorization",cHttpSend)
Please note that the format of cHttpSend depends on the format expected by your API provider. I assume that you have clear idea about it and you have filled the contents of cHttpSend accordingly
Regards
Anser
- cdmmaui
- Posts: 653
- Joined: Fri Oct 28, 2005 9:53 am
- Location: The Woodlands - Dallas - Scottsdale - London
- Contact:
Re: JSON Post and Get sample
Dear Anser,
Thank you. I changed and got the following response.
{"Type":"api_error","Message":"The request failed due to an internal error.","Code":"500","Params":[{"Name":"WINConnect.Manager","Message":"Object reference not set to an instance of an object."},{"Name":"","Message":"One or more errors occurred."}]}
The API document indicate the following format. Should I change the code?
Login and Authentication:
Calling the Login with POST method endpoint obtains an initial authToken as a cookie and creates your secure
session in the WIN application. Each API request will return a fresh authToken cookie which must be passed
back to WIN in the next API request. Cookies are short text strings which the user agent (usually your web
browser but may be an HTTP library in .NET, Java or PHP, or a command line utility such as curl) stores and
manages. The only request that does not need an initial authToken cookie value is the Login. Your application
must also set headers for Content-type: application/json and Accept: application/json in the Login POST
request.
Example of Login POST request:
POST https://www.winwebconnect.com/api/v1/Login
{ "Username": "user@company.com", "Password": "secret"}
Headers:
Content-Type: application/json
Accept: application/json
Example of Login POST response:
Headers:
Cache-Control:no-cache
Content-Encoding:gzip
Content-Length:806
Content-Type:application/json; charset=utf-8
Date:Tue, 16 Dec 2014 07:00:05 GMT
Expires:-1
Pragma:no-cache
Set-Cookie:authToken=C9F3440891B1456002C223785F2C43581A00369CE7B6021E3B00FA21618FEBC51F0483
1AD0717A4FF7EF29A0882A38B9940E9E238CFE965ABA1C581399CCA2A804D663A521023F7953D40CC19EF6C
7CED0086B6F5F8D3C7A4352111247988B4D6789876D34A526823AF18E8DC4EE44BD; expires=Tue,
23-Dec-2014 07:00:05 GMT; path=/api; HttpOnly
Vary:Accept-Encoding
Each new Set-Cookie:authToken value returned from WIN must be provided in the next GET request header as
shown below (see GET UAT API Endpoint).
Upon successful login an object containing information about the logged in user will also be returned. Your
application does not need to store or do anything with this information.
{"LastLogin": "2014-12-16T10:58:52.293529Z", "UserDetails": { "ContactID": 674, "AgentID": 184145,
"FirstName": "UAT", "LastName": "APIUser", "Email": "UAT.apiuser@company.com", "JobTitle": "Software
Application", "ContactNumber": "+91889999999", "IsActivated": true, "OperatedBy": null, "Permissions":
["airtrackingapi" ]... }
Thank you. I changed and got the following response.
{"Type":"api_error","Message":"The request failed due to an internal error.","Code":"500","Params":[{"Name":"WINConnect.Manager","Message":"Object reference not set to an instance of an object."},{"Name":"","Message":"One or more errors occurred."}]}
The API document indicate the following format. Should I change the code?
Login and Authentication:
Calling the Login with POST method endpoint obtains an initial authToken as a cookie and creates your secure
session in the WIN application. Each API request will return a fresh authToken cookie which must be passed
back to WIN in the next API request. Cookies are short text strings which the user agent (usually your web
browser but may be an HTTP library in .NET, Java or PHP, or a command line utility such as curl) stores and
manages. The only request that does not need an initial authToken cookie value is the Login. Your application
must also set headers for Content-type: application/json and Accept: application/json in the Login POST
request.
Example of Login POST request:
POST https://www.winwebconnect.com/api/v1/Login
{ "Username": "user@company.com", "Password": "secret"}
Headers:
Content-Type: application/json
Accept: application/json
Example of Login POST response:
Headers:
Cache-Control:no-cache
Content-Encoding:gzip
Content-Length:806
Content-Type:application/json; charset=utf-8
Date:Tue, 16 Dec 2014 07:00:05 GMT
Expires:-1
Pragma:no-cache
Set-Cookie:authToken=C9F3440891B1456002C223785F2C43581A00369CE7B6021E3B00FA21618FEBC51F0483
1AD0717A4FF7EF29A0882A38B9940E9E238CFE965ABA1C581399CCA2A804D663A521023F7953D40CC19EF6C
7CED0086B6F5F8D3C7A4352111247988B4D6789876D34A526823AF18E8DC4EE44BD; expires=Tue,
23-Dec-2014 07:00:05 GMT; path=/api; HttpOnly
Vary:Accept-Encoding
Each new Set-Cookie:authToken value returned from WIN must be provided in the next GET request header as
shown below (see GET UAT API Endpoint).
Upon successful login an object containing information about the logged in user will also be returned. Your
application does not need to store or do anything with this information.
{"LastLogin": "2014-12-16T10:58:52.293529Z", "UserDetails": { "ContactID": 674, "AgentID": 184145,
"FirstName": "UAT", "LastName": "APIUser", "Email": "UAT.apiuser@company.com", "JobTitle": "Software
Application", "ContactNumber": "+91889999999", "IsActivated": true, "OperatedBy": null, "Permissions":
["airtrackingapi" ]... }
Re: JSON Post and Get sample
With the below given code, I am getting the response from the server saying invalid username and password. Obviously the username and password is not the right one that I have used in the sample.
Please check with the correct username and password.
Regards
Anser
Please check with the correct username and password.
Code: Select all
#Include "Fivewin.ch"
//--------------------------------
Function Main()
Local oHttp
Try
oHttp := CreateObject( 'MSXML2.XMLHTTP' )
Catch
oHttp := CreateObject( 'Microsoft.XMLHTTP' )
End
oHttp:Open( 'POST', "https://www.winwebconnect.com/api/v1/Login", .F. )
oHttp:SetRequestHeader( "Content-Type","application/json")
oHttp:Send( '{ "Username": "user@company.com", "Password": "secret"}' )
SysRefresh()
MsgInfo(oHttp:ResponseBody)
Return
Anser
Re: JSON Post and Get sample
Saludos y Gracias,
Mensaje de Incidencia
Application
===========
Path and name: C:\FWH15\samples\PETROS.exe (32 bits)
Size: 2,938,880 bytes
Compiler version: Harbour 3.2.0dev (r1603082110)
FiveWin Version: FWH 15.03
Windows version: 6.2, Build 9200
Time from start: 0 hours 0 mins 0 secs
Error occurred at: 11/19/19, 12:53:18
Error description: (DOS Error -2147352567) WINOLE/1007 Unspecified error
(0x80004005): msxml3.dll
Stack Calls
===========
Called from: => TOLEAUTO:RESPONSEBODY( 0 )
Called from: PETROS.prg => MAIN( 22 )
System
======
CPU type: Intel(R) Core(TM) i7-4702MQ CPU @ 2.20GHz 2200 Mhz
Hardware memory: 8074 megs
Free System resources: 90 %
GDI resources: 90 %
User resources: 90 %
Windows total applications running: 4
1 ,
2 , C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.9600.17810_none_7c5b6
3 GDI+ Window, C:\Windows\WinSxS\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.9600.19457_none_dadc49905bc8c0
4 Task Switching, C:\FWH15\samples\PETROS.exe
Variables in use
================
Procedure Type Value
==========================
TOLEAUTO:RESPONSEBODY
Param 1: O Class: ERROR
MAIN
Local 1: U
Local 2: U
Code: Select all
#Include "Fivewin.ch"
//--------------------------------
Function Main()
Local oHttp
Try
oHttp := CreateObject( 'MSXML2.XMLHTTP' )
Catch
oHttp := CreateObject( 'Microsoft.XMLHTTP' )
End
oHttp:Open( 'POST', "https://petroapp-price.petro.gob.ve/price/", .F. )
oHttp:SetRequestHeader( "Content-Type","application/json")
// oHttp:Send( '{ "Username": "user@company.com", "Password": "secret"}' )
SysRefresh()
MsgInfo(oHttp:ResponseBody)
Return
Application
===========
Path and name: C:\FWH15\samples\PETROS.exe (32 bits)
Size: 2,938,880 bytes
Compiler version: Harbour 3.2.0dev (r1603082110)
FiveWin Version: FWH 15.03
Windows version: 6.2, Build 9200
Time from start: 0 hours 0 mins 0 secs
Error occurred at: 11/19/19, 12:53:18
Error description: (DOS Error -2147352567) WINOLE/1007 Unspecified error
(0x80004005): msxml3.dll
Stack Calls
===========
Called from: => TOLEAUTO:RESPONSEBODY( 0 )
Called from: PETROS.prg => MAIN( 22 )
System
======
CPU type: Intel(R) Core(TM) i7-4702MQ CPU @ 2.20GHz 2200 Mhz
Hardware memory: 8074 megs
Free System resources: 90 %
GDI resources: 90 %
User resources: 90 %
Windows total applications running: 4
1 ,
2 , C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.9600.17810_none_7c5b6
3 GDI+ Window, C:\Windows\WinSxS\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.9600.19457_none_dadc49905bc8c0
4 Task Switching, C:\FWH15\samples\PETROS.exe
Variables in use
================
Procedure Type Value
==========================
TOLEAUTO:RESPONSEBODY
Param 1: O Class: ERROR
MAIN
Local 1: U
Local 2: U
Re: JSON Post and Get sample
Which version of Windows are you using? Windows 7 ?
Which version of Internet Explorer are you using ?
Which version of Internet Explorer are you using ?
Re: JSON Post and Get sample
The problem is that you have not sent anything, that is, you have not executed the Send ()
http://forums.fivetechsupport.com/viewt ... 68#p227461
http://forums.fivetechsupport.com/viewt ... 68#p227461
C. Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
Si alguien te dice que algo no se puede hacer, recuerda que esta hablando de sus limitaciones, no de las tuyas.
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
Si alguien te dice que algo no se puede hacer, recuerda que esta hablando de sus limitaciones, no de las tuyas.