1

I'm trying to send a POST to the Smarty Streets API, but the response I'm getting back is a malformed payload. I went through the documentation on the site and I think I have everything formed correctly to send. I even used Fiddler to see what I"m sending and it looks correct but there must be something I"m missing. I'm relatively new programming. So any help would be appreciated.

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();
Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249
jckepstein
  • 11
  • 2
  • 2
    It may be the problem here is that the API requires an *array* of street inputs (if you're using a JSON payload), whereas this request is only sending a single object. – Jonathan Oliver Mar 19 '15 at 20:50

1 Answers1

0

As was commented by Jonathan Oliver, the SmartyStreets API expected a collection of input candidates. Simply modify the serialized payload to be a collection:

string jsoncvt = JsonConvert.SerializeObject(new TestAddress[] {json});
Michael Whatcott
  • 5,603
  • 6
  • 36
  • 50