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
2
  • 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. Commented Oct 13, 2020 at 6: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. The Uri class can be used to represent URIs while UriBuilder builds them Commented Oct 13, 2020 at 6:43

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.