3

I have this https://www.bookstone.com/api/rest/bookshop/gettotal?products=[{\"PRICE\":39.95,\"RECIPIENT\":{\"ZIPCODE\":\"11779\"},\"CODE\":\"F1-509\"}] This https works fine in Postman and I get the result.

{
"SERVICECHARGE": 14.99,
"SUBTOTAL": 39.95,
"TAX": 0,
"ORDERTOTAL": 54.94,
"ORDERNO": 0,
}

But in visual studio it dose not work.

var url = "https://www.bookstone.com/api/rest/bookshop/gettotal?products=[{\"PRICE\":39.95,\"RECIPIENT\":{\"ZIPCODE\":\"11779\"},\"CODE\":\"F1-509\"}]";

var response = await client.GetAsync(url);

Any ideas please?

Fattaneh
  • 143
  • 1
  • 4
  • 13
  • are you doing a POST in postman and a GET above? – Stewart_R Jul 12 '17 at 22:45
  • You need to explain what issues exactly you are having. Directly browsing to your url performs a redirect. We can't help if we don't know what parameters you are setting in POSTMAN to make this work correctly – Alexander Higgins Jul 12 '17 at 22:55
  • `But in visual studio it dose not work.` does not explain what the problem is. It could be anything. Did you get an error, a status code, anything. what does `it does not work` mean – Nkosi Jul 12 '17 at 22:56
  • Yep, I am getting a 302 redirect performing a get and a 403 error performing a post. – Alexander Higgins Jul 12 '17 at 23:00
  • I use GET in Postman with these https://www.bookstone.com/api/rest/bookshop/gettotal?products=[{\"PRICE\":39.95,\"RECIPIENT\":{\"ZIPCODE\":\"11779\"},\"CODE\":\"F1-509\"}] . The parameters are objects Recipient and products . I am asking ,what is the format for passing parameters in visual studio when the parameter is a object. – Fattaneh Jul 12 '17 at 23:12

1 Answers1

1

Fortunately I found the solution for converting array parameter to query parameter in URL.

[{"PRICE":98.5,"RECIPIENT":{"ZIPCODE":"12345"},"CODE":"abc"}]
 var queryString = JsonConvert.SerializeObject(object);
  //convert to &
 //%5b%7b%22PRICE%22%3a39.95%2c%22RECIPIENT%22%3a%7b%22ZIPCODE%22%3a%2211779%2     2%7d%2c%22CODE%22%3a%22F1-509%22%7d%5d
  var uri = WebUtility.UrlEncode(queryString);
Fattaneh
  • 143
  • 1
  • 4
  • 13