BaasBox和C#来自WP8?
我正在使用WP8设备进行测试,并尝试将本机应用程序连接到BaasBox服务。因为BaasBox还不支持WP,所以我正试图按照支持的JavaScript文档建立一个连接 使用BaasBox和C#来自WP8?,c#,visual-studio-2012,windows-phone-8,baasbox,C#,Visual Studio 2012,Windows Phone 8,Baasbox,我正在使用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 hea
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服务的登录
知道如何执行此操作吗?您连接的端点错误 前提是已在服务器上创建特定用户 你应该发帖子到:
http://openerp.homelinux.com:9000/login/
并提供自定义标题X-BAASBOX-APPCODE:1234567890
此外,目前,您还应提供登录请求的正文,如下所示:
应用程序/x-www-form-urlencoded
通常,您可以遵循curl中为rest api提供的示例:
由@eliantor提供的答案是正确的,但终点是错误的。正确的是
http://openerp.homelinux.com:9000/login
没有最后一个/
谢谢您的帮助eliantor。我已经尝试了您的解决方案,现在我可以从BaasBox服务器获得有效的响应。我现在面临的问题是如何从Header部分获取X-BB-SESSION值