C# 使用C使用WebClient对象REST API调用时出错#
我正在尝试使用以下代码发布REST API订单:C# 使用C使用WebClient对象REST API调用时出错#,c#,api,rest,webclient,uploadstring,C#,Api,Rest,Webclient,Uploadstring,我正在尝试使用以下代码发布REST API订单: 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 : " +
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;
}
我得到以下例外情况:
Input String was not in a correct format.
非常感谢您的帮助。应该有
?
在参数字符串之前的orderId之后。还可以尝试URL编码
及
希望能有所帮助。谢谢@Stewart Mbofana,能够获得输出。我使用WebClient.UploadValues()方法对NameValueCollection进行了测试,该方法也可以正常工作。