0

I'm trying to generate a token so I can get access to a server that returns a JSON file. I have read the documentation of the API of the server and it says something like this:

Verb ->POST

Protocol -> http://

Primary_domain -> api.actitudfem.com

Action -> register

Datatype -> json

Required_parameters -> appid=[unique_id]

Optional_parameters ->&name=[username]&email=[useremail]

Url ->http://api.actitudfem.com/register.json

Could anyone please help me by showing me how to get the token so I can use it to download the JSON file? Thanks

1 Answer 1

0

Use a HttpWebRequest.

Make sure you reference these:

using System;
using System.IO;
using System.Net;
using System.Text;

Then use the following:

    const string url = "http://api.actitudfem.com/register.json";

    string postData = "appid=SomeUniqueID";
    var dataBytes = Encoding.UTF8.GetBytes(postData);

    var request = (HttpWebRequest)WebRequest.Create(url);
    request.ContentLength = dataBytes.Length;
    request.ContentType = "application/x-www-form-urlencoded";
    request.Method = "POST";

    using (var postStream = request.GetRequestStream())
        postStream.Write(dataBytes, 0, dataBytes.Length);

    string json = String.Empty;
    using (var response = (HttpWebResponse)request.GetResponse())
    {
        using (var sr = new StreamReader(response.GetResponseStream()))
            json = sr.ReadToEnd();
    }

Then you can choose to append &name=[username]&email=[useremail] to the postData if required.

1
  • @OmarOsorio Np. Mark the question as answered if you are happy.
    – BlueVoodoo
    Apr 15, 2012 at 21:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.