Click here to Skip to main content
15,924,367 members
Home / Discussions / C#
   

C#

 
QuestionConvert an obsolete old REST documentation Pin
Member 1096750730-Oct-17 0:54
Member 1096750730-Oct-17 0:54 
Hey guys.

I'm struggling to use a REST API. My Problem is that only available documentation for this API is too old and it is not supported in newer versions of .net

Please help me to convert it, here is the documentation:

C#
// Using "WCF REST Starter Kit" (http://msdn.microsoft.com/en-us/netframework/cc950529.aspx)
using (var client = new HttpClient("http://rt.site.com/REST/1.0/"))
{
   client.TransportSettings.Cookies = new CookieContainer();

   var form = new HttpUrlEncodedForm();
   form.Add("user", "LOGIN");
   form.Add("pass", "PASSWORD");

   client.Post(string.Empty, form.CreateHttpContent());

   // 1. Get ticket data
   using (var request = client.Get("ticket/1234/show"))
   {
      string content = request.Content.ReadAsString();
      // Some logic
   }

   // 2. Post ticket reply with attachment
   var formPost = new HttpMultipartMimeForm();
   byte[] attachment = new byte[];
   string content = string.Empty;
         
   // Store data in attachment
   // Store data in content string ("Field: Value" line by line)
   // ...
         
   formPost.Add("content", content);
   formPost.Add("attachment_1", "attachment_1", HttpContent.Create(attachment, "application/octet-stream"));
                             
   using (var post = client.Post("ticket/1234/comment"), formPost.CreateHttpContent()))
      // Some logic
}


And here is what I have done so far:

C#
var credentials = new NetworkCredential(name, pass);
CookieContainer CookieContainer = new CookieContainer();
var handler = new HttpClientHandler {CookieContainer = CookieContainer,  Credentials = credentials };
using (var client = new HttpClient(handler))
{

    client.BaseAddress = new Uri("https://something.net");

    var form = new List<KeyValuePair<string, string>>();
    form.Add(new KeyValuePair<string, string>("user", name));
    form.Add(new KeyValuePair<string, string>("pass", pass));

    var request = new HttpRequestMessage(HttpMethod.Post, "/rt/REST/1.0");

    request.Content = new FormUrlEncodedContent(form);

    var response = await client.SendAsync(request);

    var contents = await response.Content.ReadAsStringAsync();


Please note to this comment:

The REST Interface does not support HTTP-Authentication. So you must get a valid Session-Token and submit the cookie each request. You usually get a Session-Cookie by submitting the default login form. Use variables "user" for login and "pass" for password values

Thank you very much
QuestionHow calculate Checksum for barcode code128 auto? Pin
Le@rner29-Oct-17 20:01
Le@rner29-Oct-17 20:01 
AnswerRe: How calculate Checksum for barcode code128 auto? Pin
Richard MacCutchan29-Oct-17 22:27
mveRichard MacCutchan29-Oct-17 22:27 
AnswerRe: How calculate Checksum for barcode code128 auto? Pin
Sascha Lefèvre29-Oct-17 22:27
professionalSascha Lefèvre29-Oct-17 22:27 
QuestionNo overload for method, error in c# file for Unity. Pin
Member 1349123628-Oct-17 14:33
Member 1349123628-Oct-17 14:33 
AnswerRe: No overload for method, error in c# file for Unity. Pin
Sascha Lefèvre28-Oct-17 14:47
professionalSascha Lefèvre28-Oct-17 14:47 
PraiseRe: No overload for method, error in c# file for Unity. Pin
Member 1349123628-Oct-17 15:25
Member 1349123628-Oct-17 15:25 
QuestionC# Problem extracting file from .zip created with DotNetZip Pin
manic_drummer28-Oct-17 11:58
manic_drummer28-Oct-17 11:58 
AnswerRe: C# Problem extracting file from .zip created with DotNetZip Pin
Sascha Lefèvre28-Oct-17 13:35
professionalSascha Lefèvre28-Oct-17 13:35 
AnswerRe: C# Problem extracting file from .zip created with DotNetZip Pin
Bernhard Hiller30-Oct-17 4:18
Bernhard Hiller30-Oct-17 4:18 
Questionc#Move music files in listbox up or down Pin
Member 1348924427-Oct-17 5:00
Member 1348924427-Oct-17 5:00 
AnswerRe: c#Move music files in listbox up or down Pin
Richard MacCutchan27-Oct-17 5:11
mveRichard MacCutchan27-Oct-17 5:11 
GeneralRe: c#Move music files in listbox up or down Pin
Member 1348924427-Oct-17 5:18
Member 1348924427-Oct-17 5:18 
GeneralRe: c#Move music files in listbox up or down Pin
Richard MacCutchan27-Oct-17 5:51
mveRichard MacCutchan27-Oct-17 5:51 
GeneralRe: c#Move music files in listbox up or down Pin
Member 1348924427-Oct-17 6:18
Member 1348924427-Oct-17 6:18 
GeneralRe: c#Move music files in listbox up or down Pin
Richard MacCutchan27-Oct-17 6:42
mveRichard MacCutchan27-Oct-17 6:42 
SuggestionRe: c#Move music files in listbox up or down Pin
Ralf Meier28-Oct-17 12:20
mveRalf Meier28-Oct-17 12:20 
GeneralRe: c#Move music files in listbox up or down Pin
Richard MacCutchan28-Oct-17 22:08
mveRichard MacCutchan28-Oct-17 22:08 
AnswerRe: c#Move music files in listbox up or down Pin
jschell27-Oct-17 7:39
jschell27-Oct-17 7:39 
AnswerRe: c#Move music files in listbox up or down Pin
Gerry Schmitz28-Oct-17 3:31
mveGerry Schmitz28-Oct-17 3:31 
Questionc# Need to be able to play music files that were additional items to the list box Pin
Member 1348924427-Oct-17 3:52
Member 1348924427-Oct-17 3:52 
AnswerRe: c# Need to be able to play music files that were additional items to the list box Pin
OriginalGriff27-Oct-17 3:57
mveOriginalGriff27-Oct-17 3:57 
AnswerRe: c# Need to be able to play music files that were additional items to the list box Pin
Richard Deeming27-Oct-17 4:04
mveRichard Deeming27-Oct-17 4:04 
GeneralSOLVEDRe: c# Need to be able to play music files that were additional items to the list box Pin
Member 1348924427-Oct-17 4:18
Member 1348924427-Oct-17 4:18 
AnswerRe: c# Need to be able to play music files that were additional items to the list box Pin
Gerry Schmitz27-Oct-17 4:26
mveGerry Schmitz27-Oct-17 4:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.