BaasBox and C# from WP8?

226 views Asked by At

I'm doing some test from my WP8 device and try to connect a native app to the BaasBox service. Since BaasBox doesn't have support for WP yet, i'm trying to establish a connection following the supported JavaScript documentation

The C# code using the HttpClient class:

using (var client = new HttpClient())
{
    //Send HTTP request
    //This code sets the base URI for HTTP requests, 
    //and sets the Accept header to "application/json", which tells the server to send data in JSON format
    client.BaseAddress = new Uri("http://openerp.homelinux.com:9000");
    client.DefaultRequestHeaders.Accept.Clear();
    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

    //
    BaasBoxLogin login = new BaasBoxLogin();
    login.userName = "testuser";
    login.password = "testpwd";
    login.appcode = "1234567890";

    HttpResponseMessage response = await client.PostAsJsonAsync(new Uri("http://openerp.homelinux.com:9000/console/"), login);

    if (response.IsSuccessStatusCode)
    {
        //get the uri of the created resource
        Uri gizmoResponse = response.Headers.Location;
    }
    else
    {
        this.LblToken.Text = "TokenId: NOT Found";
    }
}

When running and debugging the above code from my device the following messages is generated after trying to establish the connection:

{
    StatusCode: 404,
    ReasonPhrase: 'Not Found',
    Version: 0.0,
    Content: System.Net.Http.StreamContent,
    Headers: {
            Content-Length: 399 Content-Type: application/json; charset=utf-8
    }
}

As mentioned before, I'm using the HttpClient class. However, i'm considering to use the HttpWebRequest to achieve log in to the BaasBox service

Any idea how to perform this?

2

There are 2 answers

0
Giastfader On BEST ANSWER

The answer provided by @eliantor is correct but the endpoint is wrong. The right one is http://openerp.homelinux.com:9000/login without the last /.

1
eliantor On

The endpoint you are connecting to is wrong.

Provided the specific user has been created on the server.

You should make a post to: http://openerp.homelinux.com:9000/login/ And provide a custom header X-BAASBOX-APPCODE: 1234567890

Also, currently, you should provide the body for the login request as: application/x-www-form-urlencoded

In general you can follow the examples provided for the rest api in curl: http://www.baasbox.com/documentation/?shell#login