Hola quisiera ver si me pueden ayudar con un problema que tengo enviando y recibiendo un json entre una aplicación C#.NET (NO es ASP), al intentarlo me retorna TimeOut, lo que ejecuto en C# es lo siguiente:
WebRequest request = WebRequest.Create(string.Format("http://{0}:{1}/",IPServer,IPPort));
request.Method = "POST";
string postData = "datos=" + createJson();
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
request.Timeout = 100000;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = request.GetResponse();
Console.WriteLine(((HttpWebResponse)response).Stat usDescription);
dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
File.WriteAllText(string.Format(@"{0}/datos.json",Environment.CurrentDirectory),response FromServer);
Console.WriteLine(responseFromServer);
reader.Close();
dataStream.Close();
response.Close();
y en Node Js tengo lo siguiente:
http.createServer(function (req, res) {
//res.writeHead(200, { 'Content-Type': 'text/html' });
var queryData = "";
if(typeof callback !== 'function') return null;
if(req.method == 'POST') {
req.on('data', function(data) {
queryData += data;
/*if(queryData.length > 1e6) {
queryData = "";
response.writeHead(413, {'Content-Type': 'text/plain'}).end();
req.connection.destroy();
}*/
});
req.on('end', function() {
res.writeHead(200, { 'Content-Type': 'application/json', 'data-type': 'json' });
req.post = querystring.parse(queryData);
var data = querystring.parse(queryData);
allData(data, function (error, result) {
if (error) { logError(error, res); return; }
//res.write("Informacion Obtenida Correctamente.\r\n");
res.write(result);
res.end("");
});
});
} else {
response.writeHead(405, {'Content-Type': 'text/plain'});
response.end();
}
}).listen(port);