Trouble with UsingBasicAuthentication in Post

Posted by Rod Anderson on 07-Aug-2017 10:02

I'm new to the http client so this may be a stupid question but I can get UsingBasicAuthentication() to work with a Get Request:

httpClient  = ClientBuilder:Build()
                :Client.

// Create credentials
creds = new Credentials('smisdev.myDomain.com', 'XCDS', 'abc123').
 
req = RequestBuilder:Get('smisdev.myDomain.com/.../XCDS')
        :UsingBasicAuthentication(creds)
        :Request.

resp = httpClient:Execute(req).

But I need to perform a POST request with

UsingBasicAuthentication(creds) and an empty body.   No matter what I try I can't seem to get it to work.  Thoughts?

Posted by Peter Judge on 07-Aug-2017 11:24

Basically you need to cheat a little (and add/and remove the body).
 
httpClient = ClientBuilder:Build():Client.
 
emptyReq = RequestBuilder:Post('http://httpbin.org/post', String:Empty())
                :Request.
// Remove the entity (since there's a bug preventing it from being used)
emptyReq:Entity = ?.
// Remove the auto-added ContentType value (from the RequestBuilder call)
emptyReq:RemoveHeader('Content-Type').
               
resp = httpClient:Execute(emptyReq).
 
 
Full code at  github.com/.../post_empty_message.p
 

All Replies

Posted by Peter Judge on 07-Aug-2017 11:24

Basically you need to cheat a little (and add/and remove the body).
 
httpClient = ClientBuilder:Build():Client.
 
emptyReq = RequestBuilder:Post('http://httpbin.org/post', String:Empty())
                :Request.
// Remove the entity (since there's a bug preventing it from being used)
emptyReq:Entity = ?.
// Remove the auto-added ContentType value (from the RequestBuilder call)
emptyReq:RemoveHeader('Content-Type').
               
resp = httpClient:Execute(emptyReq).
 
 
 

This thread is closed