简体   繁体   English

WP8中的BaasBox和C#?

[英]BaasBox and C# from WP8?

I'm doing some test from my WP8 device and try to connect a native app to the BaasBox service. 我正在从WP8设备进行一些测试,并尝试将本机应用程序连接到BaasBox服务。 Since BaasBox doesn't have support for WP yet, i'm trying to establish a connection following the supported JavaScript documentation 由于BaasBox还不支持WP,因此我正在尝试根据受支持的JavaScript文档建立连接。

The C# code using the HttpClient class: 使用HttpClient类的C#代码:

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. 如前所述,我正在使用HttpClient类。 However, i'm considering to use the HttpWebRequest to achieve log in to the BaasBox service 但是,我正在考虑使用HttpWebRequest来实现登录BaasBox服务

Any idea how to perform this? 知道如何执行此操作吗?

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 您应该将帖子发布到: http://openerp.homelinux.com:9000/login/ X-BAASBOX-APPCODE: 1234567890并提供自定义标题X-BAASBOX-APPCODE: 1234567890

Also, currently, you should provide the body for the login request as: application/x-www-form-urlencoded 另外,当前,您应该提供登录请求的正文,如下所示: 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 通常,您可以在curl中遵循为其余api提供的示例: http : //www.baasbox.com/documentation/? shell#login

The answer provided by @eliantor is correct but the endpoint is wrong. @eliantor提供的答案是正确的,但端点是错误的。 The right one is http://openerp.homelinux.com:9000/login without the last / . 正确的是http://openerp.homelinux.com:9000/login没有最后一个/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM