Hi, good night!
I'm trying to post some data using .net methods, but it doesn't work.
Could you help me?
The response is 405 - Method Not Allowed
But, when I use the o ARC (Advanced Rest Client), Google Chrome's Add-on, it works well.
This is the code:
/*------------------------------------------------------------------------ File : Integra.p Purpose : Syntax : Description : Author(s) : Created : Thu Nov 15 22:58:07 BRST 2018 Notes : ----------------------------------------------------------------------*/ /* *************************** Definitions ************************** */ USING OpenEdge.Net.HTTP.RequestBuilder. USING OpenEdge.Net.HTTP.IHttpRequest. USING OpenEdge.Net.HTTP.IHttpResponse. USING OpenEdge.Net.HTTP.ClientBuilder. USING Progress.Json.ObjectModel.JsonObject. /* ******************** Preprocessor Definitions ******************** */ DEFINE VARIABLE httpUrl AS CHARACTER NO-UNDO. DEFINE VARIABLE oRequest AS IHttpRequest NO-UNDO. DEFINE VARIABLE oResponse AS IHttpResponse NO-UNDO. DEFINE VARIABLE oJson AS JsonObject NO-UNDO. /* *************************** Main Block *************************** */ httpUrl = "10.0.1.67:8091/.../get.json". oJson = new JsonObject(). oJson:Add('appId', new JsonObject()). oJson = new JsonObject(). oJson:Add('token', new JsonObject()). oJson = new JsonObject(). oJson:Add('filter', new JsonObject()). oJson = new JsonObject(). oJson:Add('date1', new JsonObject()). oJson = new JsonObject(). oJson:Add('date2', new JsonObject()). oJson = new JsonObject(). oJson:Add('activityId', new JsonObject()). oJson = new JsonObject(). oJson:Add('taskIdCode', new JsonObject()). /* { "appId" : "totvs.1", "token" : "tm+m/bhBMk+fc6a/2ScztLdY+PzGUhih1oNUiGKv97lfHAeiRclBKyU6Wi2elCri", "filter" : { "date1" : null, <RUBIA> ENVIAR O PERÍODO TANTO PARA REPORTE DE OP QUANTO TRANSFERÊNCIA "date2" : null, <RUBIA> ENVIAR O PERÍODO TANTO PARA REPORTE DE OP QUANTO TRANSFERÊNCIA "activityId" : 0, "taskIdcode" : null, "materialId" : null, <RUBIA> SE PRECISAR DOS DADOS DE UM ITEM ESPECÍFICO "originCenterId" : null, <RUBIA> DEPÓSITO ORIGEM (INFORMAR SEMPRE PARA TRANSFERÊNCIA) "destCenterId" : null, <RUBIA> DEPÓSITO DESTINO (INFORMAR SEMPRE PARA TRANSFERÊNCIA) "batchIdcode" : null, "prodIdcode" : null, <RUBIA> INFORMAR A ORDEM DE PRODUÇÃO "appId" : "totvs.1" } } */ oRequest = RequestBuilder:Put(httpUrl, oJson) :AcceptJson() :Request. oResponse = ClientBuilder:Build():Client:Execute(oRequest). MESSAGE oResponse:StatusCode SKIP oResponse:StatusReason SKIP VIEW-AS ALERT-BOX.
/*------------------------------------------------------------------------ File : Integra.p Purpose :
Syntax :
Description :
Author(s) : Created : Thu Nov 15 22:58:07 BRST 2018 Notes : ----------------------------------------------------------------------*/
/* *************************** Definitions ************************** */USING OpenEdge.Net.HTTP.RequestBuilder.USING OpenEdge.Net.HTTP.IHttpRequest.USING OpenEdge.Net.HTTP.IHttpResponse.USING OpenEdge.Net.HTTP.ClientBuilder.USING Progress.Json.ObjectModel.JsonObject./* ******************** Preprocessor Definitions ******************** */DEFINE VARIABLE httpUrl AS CHARACTER NO-UNDO.DEFINE VARIABLE oRequest AS IHttpRequest NO-UNDO.DEFINE VARIABLE oResponse AS IHttpResponse NO-UNDO.DEFINE VARIABLE oJson AS JsonObject NO-UNDO./* *************************** Main Block *************************** */ httpUrl = "10.0.1.67:8091/.../get.json". oJson = new JsonObject().oJson:Add('appId', new JsonObject()).oJson = new JsonObject().oJson:Add('token', new JsonObject()).oJson = new JsonObject().oJson:Add('filter', new JsonObject()).oJson = new JsonObject().oJson:Add('date1', new JsonObject()).oJson = new JsonObject().oJson:Add('date2', new JsonObject()).oJson = new JsonObject().oJson:Add('activityId', new JsonObject()).oJson = new JsonObject().oJson:Add('taskIdCode', new JsonObject()).
/*{ "appId" : "totvs.1", "token" : "tm+m/bhBMk+fc6a/2ScztLdY+PzGUhih1oNUiGKv97lfHAeiRclBKyU6Wi2elCri", "filter" : { "date1" : null, <RUBIA> ENVIAR O PERÍODO TANTO PARA REPORTE DE OP QUANTO TRANSFERÊNCIA "date2" : null, <RUBIA> ENVIAR O PERÍODO TANTO PARA REPORTE DE OP QUANTO TRANSFERÊNCIA "activityId" : 0, "taskIdcode" : null, "materialId" : null, <RUBIA> SE PRECISAR DOS DADOS DE UM ITEM ESPECÍFICO "originCenterId" : null, <RUBIA> DEPÓSITO ORIGEM (INFORMAR SEMPRE PARA TRANSFERÊNCIA) "destCenterId" : null, <RUBIA> DEPÓSITO DESTINO (INFORMAR SEMPRE PARA TRANSFERÊNCIA) "batchIdcode" : null, "prodIdcode" : null, <RUBIA> INFORMAR A ORDEM DE PRODUÇÃO "appId" : "totvs.1" }}*/ oRequest = RequestBuilder:Put(httpUrl, oJson) :AcceptJson() :Request. oResponse = ClientBuilder:Build():Client:Execute(oRequest).MESSAGE oResponse:StatusCode SKIP oResponse:StatusReason SKIPVIEW-AS ALERT-BOX.
I would try to get the 11.6.4 procedure libraries if you can. In general, get to 11.6.4 since it's the latest 11.6x service pack.
To read the response, look at the Entity property on the response object. If it's JSON you can cast it to a JsonObject and work with it there. There are some examples of using the HTTP client that may help, at github.com/.../http_client .
Working with JsonObjects is quite simple but quite verbose - you end up using a lot of intermediary variables. So for this
oJson:Add('filter', new JsonObject()).
oJson = new JsonObject().
oJson:Add('date1', new JsonObject()).
oJson = new JsonObject().
oJson:Add('date2', new JsonObject()).
oJson = new JsonObject().
you can rewrite it
def var filterJson as JsonObject.
filterJson = new JsonObject().
oJson:Add('filter', filterJson).
filterJson:AddNull('date1').
filterJson:AddNull('date2').
filterJson:Add('activityId', 0).
// etc
Try to change this line here
oRequest = RequestBuilder:Put(httpUrl, oJson)
to
oRequest = RequestBuilder:Post(httpUrl, oJson)
You are writing "Post" data, but you are using the "Put" method.
Try to change this line here
oRequest = RequestBuilder:Put(httpUrl, oJson)
to
oRequest = RequestBuilder:Post(httpUrl, oJson)
Mike, its work, but now, how can I take the data response?
And, how can I do then "new" block, using ADD, like "filter" : {
/* { "appId" : "totvs.1", "token" : "tm+m/bhBMk+fc6a/2ScztLdY+PzGUhih1oNUiGKv97lfHAeiRclBKyU6Wi2elCri", "filter" : { "date1" : null, <RUBIA> ENVIAR O PERÍODO TANTO PARA REPORTE DE OP QUANTO TRANSFERÊNCIA "date2" : null, <RUBIA> ENVIAR O PERÍODO TANTO PARA REPORTE DE OP QUANTO TRANSFERÊNCIA "activityId" : 0, "taskIdcode" : null, "materialId" : null, <RUBIA> SE PRECISAR DOS DADOS DE UM ITEM ESPECÍFICO "originCenterId" : null, <RUBIA> DEPÓSITO ORIGEM (INFORMAR SEMPRE PARA TRANSFERÊNCIA) "destCenterId" : null, <RUBIA> DEPÓSITO DESTINO (INFORMAR SEMPRE PARA TRANSFERÊNCIA) "batchIdcode" : null, "prodIdcode" : null, <RUBIA> INFORMAR A ORDEM DE PRODUÇÃO "appId" : "totvs.1" } } */
I would try to get the 11.6.4 procedure libraries if you can. In general, get to 11.6.4 since it's the latest 11.6x service pack.
To read the response, look at the Entity property on the response object. If it's JSON you can cast it to a JsonObject and work with it there. There are some examples of using the HTTP client that may help, at github.com/.../http_client .
Working with JsonObjects is quite simple but quite verbose - you end up using a lot of intermediary variables. So for this
oJson:Add('filter', new JsonObject()).
oJson = new JsonObject().
oJson:Add('date1', new JsonObject()).
oJson = new JsonObject().
oJson:Add('date2', new JsonObject()).
oJson = new JsonObject().
you can rewrite it
def var filterJson as JsonObject.
filterJson = new JsonObject().
oJson:Add('filter', filterJson).
filterJson:AddNull('date1').
filterJson:AddNull('date2').
filterJson:Add('activityId', 0).
// etc
Thanks a Lot guys.
Someone knows how can I return the code after create JsonObjects?
I need to know it my code is in the correct structure.