我正在使用我的 WP8 设备进行一些测试,并尝试将本机应用程序连接到 BaasBox 服务。由于 BaasBox 尚不支持 WP,我正在尝试按照支持的 JavaScript 文档建立连接
使用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";
}
}
从我的设备运行和调试上述代码时,在尝试建立连接后会生成以下消息:
{
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服务
知道如何执行此操作吗?