WP8中的BaasBox和C#? [英] BaasBox and C# from WP8?

查看:118
本文介绍了WP8中的BaasBox和C#?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用WP8设备进行一些测试,并尝试将本机应用程序连接到BaasBox服务.由于BaasBox还不支持WP,因此我正在尝试根据支持的JavaScript文档建立连接

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

使用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
    }
}

如前所述,我正在使用HttpClient类.但是,我正在考虑使用HttpWebRequest来实现登录BaasBox服务

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?

推荐答案

@eliantor提供的答案是正确的,但端点是错误的.右边的是http://openerp.homelinux.com:9000/login,没有最后一个/.

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 /.

这篇关于WP8中的BaasBox和C#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆