Forum Discussion
Web.Contents with the Content option is only supported when connecting anonymously
Hi,
I am trying to connect to a data source via a POST request. To do this, I am creating a blank query that follows the following schema:
let
url = "",
body = "{}",
header = [#"Content-Type"="application/json", #"Authoritation" = "Basic xxxxxxxx"],
result = Json.Document(Web.Contents(url,[Headers = header, Content=Text.ToBinary(body)]))
in
result
Actually, it is giving the following error: Web.Contents with the Content option is only supported when connecting anonymously. How could a POST request be made that has body and basic authentication?
Thanks.
- Anonymous3 years ago
Hi Anonymous ,
The error message you received indicates that the web service you are trying to connect to does not support sending data with authentication. One way to work around this issue is to encode the authentication information in the URL itself.
To do this, you can modify your code as follows:
let url = "https://username:[email protected]/data", body = "{}", header = [#"Content-Type"="application/json"], result = Json.Document(Web.Contents(url,[Headers = header, Content=Text.ToBinary(body)])) in resultReplace "username" and "password" with your actual credentials, and "api.example.com/data" with the URL of the web service you are trying to connect to. This should allow you to make a POST request with a body and basic authentication.
How to Get Your Question Answered Quickly
If it does not help, please provide more details.
Best Regards
Community Support Team _ RongtieIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
2 Replies
- AnonymousNot applicable
Hi Anonymous ,
The error message you received indicates that the web service you are trying to connect to does not support sending data with authentication. One way to work around this issue is to encode the authentication information in the URL itself.
To do this, you can modify your code as follows:
let url = "https://username:[email protected]/data", body = "{}", header = [#"Content-Type"="application/json"], result = Json.Document(Web.Contents(url,[Headers = header, Content=Text.ToBinary(body)])) in resultReplace "username" and "password" with your actual credentials, and "api.example.com/data" with the URL of the web service you are trying to connect to. This should allow you to make a POST request with a body and basic authentication.
How to Get Your Question Answered Quickly
If it does not help, please provide more details.
Best Regards
Community Support Team _ RongtieIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Little-MikeNew Member
Please correct the typo in your code sample: it must read "Authorization" instead of "Authoritation".