Ojalá me puedan ayudar para enviar data a un APi Rest:
Esta es lo que dice documentación: Headers Headers must be set in order to authenticate and link the information to your account. MiEmpresa API requires the following headers:
X-AUTH-TOKEN: Your API key in order to link all your API activity to your account, this can be created through the web interface in Settings -> Advanced Settings.
Content-Type: As seen before, MiEmpresa's API is built to work in a JSON data format, so you must specify the request header to be 'Content-Type:application/json'.
El metodo es POST, y he generado mi LLave para conectarme:
El código que tengo es la que sigue:
private void button2_Click(object sender, EventArgs e)
{
var request = (HttpWebRequest)WebRequest.Create(strURL);
var jsondata = textBox1.Text;
request.Method = "POST";
request.ContentType = "application/json";
NetworkCredential credentials = new NetworkCredential(strName, strKey);
request.Credentials = credentials;
using (var streamWriter = new StreamWriter(request.GetRequestStream()))
{
streamWriter.Write(strJsonData);
streamWriter.Flush();
streamWriter.Close();
}
try
{
using (WebResponse response = request.GetResponse())
{
using (Stream strReader = response.GetResponseStream())
{
if (strReader == null) return;
using (StreamReader objReader = new StreamReader(strReader))
{
string responseBody = objReader.ReadToEnd();
Console.WriteLine(responseBody);
}
}
}
}
catch (WebException ex)
{
// Handle error
}
}
y el error es: "Error en el servidor remoto: (401) No autorizado."