Page 1 of 1

How to make a PUT command [Solved]

Posted: Sat May 23, 2020 12:18 pm
by marcopuppo
I need to send to a webservice a PUT command

The following request was created using PAW on a Macintosh and worked.
----
PUT /PagoInReteWS/rest/pianodeicontiservice/crea HTTP/1.1
Authorization: Basic <base64 user and password>
Content-Type: application/json; charset=utf-8
Host: collaudo.pubblica.istruzione.it
Connection: close
User-Agent: Paw/3.1.10 (Macintosh; OS X/10.13.6) GCDHTTPRequest
Content-Length: 307

{"codiceDebole":"XXX","annoScolastico":XXXX,"flusso":"P3","fornitore":"XXXX","versioneSw":"XXXX","user":"XXXX","theListPianoDeiConti":[{"annoFinanziario":2020,"codiceScuola":"XXXXX","aggregato":"09","voce":"09","sottovoce":"01","descrizioneConto":"Alienazione di impianti prova"}]}
-------
I'm not able to replicate the command using tsNet library with tsNetCustomSync or tsNetCustom. Maybe i should use some other command ?

Thanks

Marco Puppo

Re: How to make a PUT command

Posted: Sat May 23, 2020 6:02 pm
by jacque
I do it with a simple "put" command:

put tJSON into url "https://domain.path"

Re: How to make a PUT command

Posted: Sat May 23, 2020 8:23 pm
by matthiasr
Marco,

it´s difficult to say what is going wrong, if you do not post a sample of your code.

I am no expert in webservices, but tsNetCustomUploadSync or tsNetCustomUpload should do

This is for tsNEtCustomUploadSync

tsNetCustomUploadSync(pURL, pRequest, xHeaders, pData, rOutHeaders, rResult, rBytes, [pSettings])

pURL contains the server URL
pRequest contains the request like put/delete or patch or whatever
xHeaders - see dictionary
pData contains the data you want to send (put) to the web service
rOutHeaders - will contain the headers that were returned from the server on completion.
rResult - will contain the status code sent by the server to the last command that was issued during the transfer.
rBytes - will contain the number of bytes that were downloaded/transfered during the connection
pSettings - is an array. see dictionary and the explanations below.

Your connection seems to need basic authentication. So you should set at least the username and password in pSettings:

put YOURUSERNAME into pSettings["username"]
put YOURPASSWORD into pSettings["password"]

tsNET normally should be able to detect the authentication method, but you could force tsNET to use basic authentication right away
put TRUE into pSettings["force_basic_auth"]

and a last one..
For testing i am using also
put TRUE into pSettings["no_reuse"]

This forces tsNET to close the connection to the server after the execution. If not set, tsNET leaves the connection open to the server for future connections. Especially when testing it might be good to let tsNET closing the connection after the command was executed.

As written already, i am not very firm with web services, but maybe the above lines are a good start for you.

HTH

Regards,
Matthias

Re: How to make a PUT command

Posted: Sun May 24, 2020 2:41 am
by bangkok
Regarding PUT I found a message from Charles (the creator of tsNet) :

"You can use the tsNetCustom* functions to issue any HTTP(S) request type you require (including PATCH and PUT). The tsNetUpload* functions are also effectively just a PUT request when using the HTTP(S) protocols."

So I guess, this is the command you're looking for.

I wish we have a comprehensive set of real examples for each tsNet command.

We have this :

https://www.techstrategies.com.au/tsnet ... reference/

It's a start.

The library is rich, full of parameters (look at version 1.4 !)...

Personally I use only tsNetPostSync (for regular POST). But with a proper set of examples/guidelines, I would probably try other things.

Re: How to make a PUT command

Posted: Sun May 24, 2020 9:17 am
by marcopuppo
Thank you for yor help, i will try on monday.

On late saturday and on sunday the server is not working.

In italy government server follow office rules. Not open on holidays.

Thank you

Marco

Re: How to make a PUT command

Posted: Thu Jun 18, 2020 11:26 am
by marcopuppo
It worked with tsNetCustomUploadSync.

Thank you very much.

Marco