0

In VBA, I used this query string to send variables to the API and save it to the database. Is possible to do the same in C#? and how are the variables marked in the query string and send it with HttpClient?

VBA Query String :

sDataPairs = "mail_from=" & strFrom & "&mail_to=" & strTo & "&url_attribute=" & strWebLink

for example: "mail_from is the name of the column in the database, strFrom is a variable from outlook active current item.

VBA result:

https://my.address.com/api?=mail_from=strFrom&mail_to=strTo&url_attribute=strWebLink
Fahim Uz Zaman
  • 444
  • 3
  • 6
Novice
  • 363
  • 10
  • 32
  • Have you tried anything? Tried to concatenate the strings? BTW that VBA code *doesn't* produce the string you posted. Which is an invalid URL to begin with. It produces only the part starting from `mail_from` to the end. – Panagiotis Kanavos Oct 13 '20 at 06:37
  • You can just use `+` to concatenate strings, but as the VBA results shows, this can produce invalid results. There are classes in both .NET and .NET Core that allow you to generate a query string from a list of key/value pairs that take care of properly encoding keys and values. In .NET Core, it's [WebUtilities.QueryHelpers](https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.webutilities.queryhelpers?view=aspnetcore-3.1). The `Uri` class can be used to represent URIs while [UriBuilder](https://docs.microsoft.com/en-us/dotnet/api/system.uribuilder?view=netcore-3.1) builds them – Panagiotis Kanavos Oct 13 '20 at 06:43

0 Answers0