L lancaster Member Licensed User Longtime User May 14, 2019 #1 I am attempting to make a PUT request to a REST API setting the headers of Content-Type:application/json and Accept:application/json and of course passing a valid json string in the body of the request. The remote service returns "HttpMediaTypeNotSupportedException" "Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported" where clearly this is not the content-type I am specifying in the header. Ironically I can use POSTMAN with exactly the same headers and json payload and the remote service accepts the request. This suggests to me that the HTTP client stack is inserting an alternative Content-Type header. Has anyone encountered similar? Thanks
I am attempting to make a PUT request to a REST API setting the headers of Content-Type:application/json and Accept:application/json and of course passing a valid json string in the body of the request. The remote service returns "HttpMediaTypeNotSupportedException" "Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported" where clearly this is not the content-type I am specifying in the header. Ironically I can use POSTMAN with exactly the same headers and json payload and the remote service accepts the request. This suggests to me that the HTTP client stack is inserting an alternative Content-Type header. Has anyone encountered similar? Thanks
Erel B4X founder Staff member Licensed User Longtime User May 14, 2019 #2 Where is the relevant code? Upvote 0
K keirS Well-Known Member Licensed User Longtime User May 15, 2019 #3 If you are not already doing so you should use HttJob.GetRequest().SetContentType and not HttJob.GetRequest().SetHeader for content type. You can find out exactly what is being sent to the server by using this code posted by Erel: https://www.b4x.com/android/forum/threads/httpjob-get-a-request-as-string.103494/#post-648754 Upvote 0
If you are not already doing so you should use HttJob.GetRequest().SetContentType and not HttJob.GetRequest().SetHeader for content type. You can find out exactly what is being sent to the server by using this code posted by Erel: https://www.b4x.com/android/forum/threads/httpjob-get-a-request-as-string.103494/#post-648754