RE: VW 7.10 HTTP ContentType
Steven Kelly <[email protected]> Mon, 5 Sep 2022 11:17:26 +0000
| Newsgroups | gmane.comp.lang.smalltalk.vwnc |
|---|---|
| Message-ID | <HE1P194MB0027262D651D9B1FF0B86A78A67F9@HE1P194MB0027.EURP194.PROD.OUTLOOK.COM> |
Hi, HttpClient really shouldn’t be trying to guess the ContentType from the payload. The caller should set up the right ContentType before starting to send anything (including the headers, which is where the Content-type is actually sent). See “Requesting an HTTP document” in doc\NetClientDevGuide.pdf, e.g. | httpClient request response | httpClient := HttpClient new. request := HttpRequest post: 'https://urldefense.com/v3/__http://someserver.com/jsonSink__;!!DZ3fjg!6OcoBnFO_dd7RwACqOpSzuzEh1NJ4mqA_6p8hE78gzoBTlykmBA33gThoqwTiXknGkXL-FIm_-r7Zu3w$ '. request contentType: 'application/json'. "insert your own code here to add the json into the request …" response := httpClient executeRequest: request. The HttpClient is more about the connection, the HttpRequest is one message that is sent over that connection. Often you want the same client to send many requests (httpClient usePersistentConnection), possibly with different methods and ContentTypes, so the request is a more natural place than the client for setting ContentType. All the best, Steve From: [email protected] <[email protected]> On Behalf Of Shaping Sent: Monday, September 5, 2022 9:45 AM To: [email protected] Subject: [vwnc] VW 7.10 Hi. Has anyone noticed that HttpClient, when preparing a POST HttpRequest with a JSON payload, doesn’t set the request’s ContentType to ‘application/json’, as it should? Instead the default ‘text/plain’ remains. The client isn’t making any effort to check the body’s payload, discover that its JSON, and then set the ContentType. I was able to get the request to work by hacking-in the correct ContentType, but this clearly needs to be done more carefully in the right place. Is this, by any chance, a known problem, and has it been fixed? Shaping