West Wind Internet and Client Tools
HTTP PUT Request
Gravatar is a globally recognized avatar based on your email address. HTTP PUT Request
  Stuart McKay
  All
  May 4, 2017 @ 04:11pm

I have used the httpget to send get requests and post requests but have come across a situation where I need to perform a put request.

This is the curl example that is provided by the vendor that a customer of ours wants to integration our app with.

I'm looking in the documentation but don't see anything to handle this situation. Is there a nhttppostmode number to use for a put?

Any insight would be greatly appreciated.

Stuart McKay

curl -X PUT -H "Authorization: Bearer 66126b8888baabab80faa047656a7e72" -H "Cache-Control: no-cache" -H "Content-Type: multipart/form-data" -F "headings=Y" -F "fieldseparator=COMMA" -F "quotecharacter=NONE" -F "uploadspecs=[{"columnHeading":"Email","ignoreColumn":"N","columnIndex":0,"columnType":"EMAIL"},{"columnHeading":"First Name","ignoreColumn":"N","columnIndex":1},{"columnHeading":"Last Name","ignoreColumn":"N","columnIndex":2},{"columnHeading":"Company","ignoreColumn":"N","columnIndex":3}]" -F "file=@/path/to/file.csv" -F "mergespecs=[{"dstListId":"l-08fd","mergeMode":"UPSERT","columnMap":[]}]" -F "listId=l-08fd" https://restapi.actonsoftware.com/api/1/list/l-08fd
Gravatar is a globally recognized avatar based on your email address. re: HTTP PUT Request
  Rick Strahl
  Stuart McKay
  May 4, 2017 @ 07:06pm

To send PUT requests just set loHttp.cHttpVerb = "PUT" and post your data just like a POST operation.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: HTTP PUT Request
  Stuart McKay
  Rick Strahl
  May 8, 2017 @ 05:51pm

Appreciate the quick reply! Still not getting this to work, I can setup the request in postman and get valid response but receive error when trying of VFP.

Not sure if you are able but I the request can be viewed via the following url: http://requestb.in/1gc9t6a1?inspect

The top entry is coming from VFP/WestWind, the bottom is coming from Postman. I see two differences, from Westwind ReguestBin is not reporting any form/post parameters where Postman is and in the postman entry after the file to send is specified I see ContentType entry.

Stuart

Gravatar is a globally recognized avatar based on your email address. re: HTTP PUT Request
  Rick Strahl
  Stuart McKay
  May 8, 2017 @ 07:54pm

I'm not sure - it could be the content type on the file sent... but I doubt it. Otherwise the data looks pretty much the same (without looking real close).

Latest version of Client Tools (6.10) lets you specify the content type via AddPostKey() - although I'm not 100% sure if it made the release or if it came after. I ran into an issue with that with file uploads a while back as well.

Check out the latest version and see if it's there. If not I'll post the code fix here which is pretty minor.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: HTTP PUT Request
  Rick Strahl
  Stuart McKay
  May 8, 2017 @ 08:16pm

So I checked the latest wwHttp release in Client Tools 6.10 and it's not there - that change was made just after it was released (it's on the Web Connection change list but not released with that either).

So, here's the updated code for AddPostKey:

************************************************************************
* wwHTTP :: AddPostKey
*********************************
***  Function: Adds POST variables to the HTTP request
***    Assume: depends on nHTTPPostMode setting
***      Pass: 
***    Return:
************************************************************************
FUNCTION AddPostKey(tcKey as string, tcValue as string, ;
                   llFileName as Boolean, lcContentType as string) as void
LOCAL lcOldAlias
tcKey=IIF(VARTYPE(tcKey)="C",tcKey,"")

IF tcKey="RESET" OR PCOUNT() = 0
   THIS.cPostBuffer = ""
   RETURN
ENDIF

*** If we post a raw buffer swap parms
IF PCOUNT() < 2
   tcValue = tcKey
   tcKey = ""
ENDIF

*** Force to string
IF(VARTYPE(tcValue)!="C")
  tcValue = TRANSFORM(tcValue)
ENDIF

IF !EMPTY(tcKey)
   DO CASE
    *** Url Encoded
    CASE THIS.nhttppostmode = 1         
         THIS.cPostBuffer = this.cPostBuffer + IIF(!EMPTY(this.cPostBuffer),"&","") + ;
                            tcKey +"="+ URLEncode(tcValue) 
      *** Multi-part formvars and file
    CASE this.nHttpPostMode = 2
      *** Check for File Flag -  HTTP File Upload - Second parm is filename
      IF llFileName
      	 THIS.cPostBuffer = THIS.cPostBuffer + "--" + MULTIPART_BOUNDARY + CRLF + ;
            [Content-Disposition: form-data; name="]+tcKey+["; filename="] + JUSTFNAME(tcValue) + ["]+CRLF
         IF !EMPTY(lcContentType)
            this.cPostBuffer =	this.cPostBuffer + "Content-Type: " + lcContentType + CRLF
         ENDIF
         this.cPostBuffer = this.cPostBuffer + CRLF
	     this.cPostBuffer = this.cPostBuffer + FILETOSTR(FULLPATH(tcValue))
	     this.cPostBuffer = this.cPostBuffer + CRLF
      ELSE
      	 this.cPostBuffer = this.cPostBuffer +"--" + MULTIPART_BOUNDARY + CRLF + ;
            [Content-Disposition: form-data; name="]+tcKey+["]+CRLF
         IF !EMPTY(lcContentType)
            this.cPostBuffer =	this.cPostBuffer + "Content-Type: " + lcContentType + CRLF
         ENDIF
         this.cPostBuffer = this.cPostBuffer + CRLF
         this.cPostBuffer = this.cPostBuffer + tcValue + CRLF
      ENDIF
   ENDCASE
ELSE
   *** If there's no Key post the raw buffer
   this.cPostBuffer = this.cPostBuffer +tcValue
ENDIF

ENDFUNC

This will add the content type for your file as long as you pass the content-type parameter to AddPostKey() for the CSV file.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: HTTP PUT Request
  Stuart McKay
  Rick Strahl
  May 10, 2017 @ 05:43pm

Appreciate all the help, will try on Friday.

Gravatar is a globally recognized avatar based on your email address. re: HTTP PUT Request
  Rick Strahl
  Michael B
  Mar 23, 2019 @ 12:58pm

Where is that error coming from? That's coming from the server I suppose?

FWIW commonly the HTTP verbs are in UPPER CASE. So try using loHttp.cHttpVerb="DELETE" and see if that helps. Some server side frameworks maybe explicitly checking the verb and if it doesn't match exactly, fail.

+++ Rick ---

© 1996-2019