我正在尝试向 Smarty Streets API 发送 POST,但我得到的响应是格式错误的有效负载。我浏览了网站上的文档,我认为我的所有内容都已正确发送。我什至使用 Fiddler 来查看我发送的内容,它看起来是正确的,但一定有我遗漏的东西。我是相对较新的编程。所以任何帮助将不胜感激。
string url = Uri.EscapeUriString("http://api.smartystreets.com/street-address?auth-id=Id&auth-token=token");
var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
TestAddress json = new TestAddress();
json.street = "11 Phelan Ave, San Francisco, CA";
string jsoncvt = JsonConvert.SerializeObject(json);
byte[] byteArray = Encoding.UTF8.GetBytes(jsoncvt);
httpWebRequest.ContentLength = byteArray.Length;
httpWebRequest.Host = "api.smartystreets.com";
httpWebRequest.ContentType = "application/json";
httpWebRequest.Accept= "application/json";
httpWebRequest.Method = "POST";
Stream dataStream = httpWebRequest.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();