5

On C#, I'm printing the JSONified string that I'm sending to the console, and it reads as

 { "message" : "done", "numSlides" : 1, "slides" : [{ "num" : 1, "key" : "530d8aa855df0c2d269a5a5853a47a469c
52c9d83a2d71d9/1slide/Slide1_v8.PNG" }], "bucket" : "xx.xxxxxxxxxx", "error"
: null, "wedge" : false, "tenant" : null, "name" : null }

Then I do this to convert it to a byte array and send it

WebRequest request = WebRequest.Create(Program.api +"/"+ route);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";

//Get the request stream
Stream dataStream = request.GetRequestStream();
byte[] byteArray = Encoding.UTF8.GetBytes(myString);
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();

And on the node.js side, I get this when console.logging res.body:

{ '{ "message" : "done", "numSlides" : 1, "slides" : ': { '{ "num" : 1, "key" : "530d8aa855df0c2d269a5a5853a47a469c52c9d83a2d71d9/1slide/Slide1_v8.PNG" }], "bucket" : "xx.xxxxxxxxxx", "error" : null, "wedge" : false, "tenant" : null, "name" : null ': '' } }

That doesn't look like valid JSON. What happened? How can I send and receive the proper data?

1 Answers1

1

I was having a similar problem when testing a node server I was writing. The issue ended up being with the content type of the request. I believe that might be your issue as well.

I'm thinking that the content type you want is "application/json".

See This Post for more info

Community
  • 1
  • 1