troubleshooting Question

How to send String Array ( string [] )in Request Params for REST API in C#?

Avatar of rich brown
rich brown asked on
* arraysC#REST
6 Comments1 Solution167 ViewsLast Modified:
How to send String Array ( string [] )in Request Params for REST API in C#?


This does not work.

public string GetLocation(string [] myItems)
{

           //var item = myItems;
            var item = "[\"Alabama\", \"Texas\"]";   //Test    
            var regionCode = "South";


            var url = $"https://MyLocation.com/api/GetLocation?MySearch={ item }&region={ regionCode }";

            var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
            httpWebRequest.Method = "POST";

            var strResult = string.Empty;

            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                var result = streamReader.ReadToEnd();
                strResult = result;
            }

            string myMsgResult = strResult;


}
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros