
tiagomacul
Mega Sage
Options
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 02-20-2018 11:08 AM
Testing webservice C#
Login - Really - select from sys_user
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
request.Method = "Get";
request.KeepAlive = true;
request.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
request.UseDefaultCredentials = true;
request.Credentials = new System.Net.NetworkCredential(testuser, testPass, "");
request.ContentType = "application/json";
try
{
System.Net.HttpWebResponse response;
response = (System.Net.HttpWebResponse)request.GetResponse();
using (System.IO.StreamReader reader = new System.IO.StreamReader(response.GetResponseStream()))
{
returnrest = reader.ReadToEnd();
}
autenticado = true;
}
catch (Exception Error)
{
returnMsg = Error.Message;
returnrest = "ERROR:" + Error.Source;
autenticado = false;
}
Request
retorno = false;
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
request.Method = "POST";
request.KeepAlive = true;
request.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
request.UseDefaultCredentials = true;
request.Credentials = new System.Net.NetworkCredential(user, password, "");
request.ContentType = "application/json";
string postData = "{ 'state':'" + state + "', " +
"'short_description':'TEST::." + short_desc + "',";
postData += "'description' : '" + description + "',";
postData += "'contact_type' : '" + contacttype +"', ";
postData += "'priority':'4'}";
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentLength = byteArray.Length;
System.IO.Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
System.Net.HttpWebResponse response;
System.Net.WebResponse vwebresponse;
try
{
//response = (System.Net.HttpWebResponse)request.GetResponse();
vwebresponse = request.GetResponse();
retorno = true;
}
//catch (System.Net.WebException Error)
catch (Exception Error)
{
rtbResponse.Text += "\n Error.Source: " + Error.Source;
rtbResponse.Text += "\n Error.Message: " + Error.Message;
}
.
Conteúdos Servicenow em Português
Labels:
- 904 Views