Hi ,
I am trying to use Rest API using asp.net C#.
I am able to Create a token.
But when i am trying to Create a Document, I am not getting any response. The application is getting timed out.
Please find the code used below:
string getcreateurl = "http://localhost/otcs/cs.exe/api/v1/nodes?";
RestClient client = new RestClient(getcreateurl, HttpVerb.POST, token);
string filemime = GetMimeType(label5.Text);
FileInfo info = new FileInfo(label5.Text);
string filename = info.Name;
byte[] bytefile = System.IO.File.ReadAllBytes(label5.Text);
string param = "type=144;parent_id=" + textBox4.Text + ";file=" + label5.Text + ";file_content_type=" + filemime + ";file_filename=" + filename;
var result = client.MakeUploadRequest(getcreateurl + param, bytefile);
public string MakeUploadRequest(string req,byte[] bytes)
{
try
{
var request = (HttpWebRequest)WebRequest.Create(req);
request.Method = Method.ToString();
//request.ContentLength = contlength;
request.ContentType = ContentType;
request.Headers.Add(authtype, OTCSTicket);
request.GetRequestStream().Write(bytes, 0, bytes.Length);
using (var response = (HttpWebResponse)request.GetResponse())
{
var responseValue = string.Empty;
if (response.StatusCode != HttpStatusCode.OK)
{
var message = String.Format("Request failed. Received HTTP {0}", response.StatusCode);
throw new ApplicationException(message);
}
// grab the response
using (var responseStream = response.GetResponseStream())
{
if (responseStream != null)
using (var reader = new StreamReader(responseStream))
{
responseValue = reader.ReadToEnd();
}
}
return responseValue;
}
}
catch
{ throw; }
}