Error in using WebClient object REST API call using C#

api, c#, rest, uploadstring, webclient

Solution

There should be a

?

after the orderId before the parameters' string. Also try URL Encoding

http://msdn.microsoft.com/en-us/library/system.web.httputility.urlencode(v=vs.110).aspx

and

http://msdn.microsoft.com/en-us/library/zttxte6w(v=vs.110).aspx

Hope it helps.

Problem

I am trying to POST an order to REST API using the below code: ``` string URI = "https://api.myTrade.com/s1/order/" + orderId; string myParameters = "symbol=AAPL&duration=day&side=buy&quantity=1&type=limit&price=1"; Console.Write("Parameters : " + myParameters + "\n"); using (WebClient wc = new WebClient()) { wc.Headers[HttpRequestHeader.Authorization] = "Bearer " + token wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; wc.Headers[HttpRequestHeader.Accept] = "application/json"; string responsebody = wc.UploadString(URI, myParameters); //Console.Write("Output : " + responsebody + " "); dynamic dynObj = JsonConvert.DeserializeObject(responsebody); return responsebody; } ``` I am getting the following exception: ``` Input String was not in a correct format. ``` Any help is greatly appreciated.

Original source