0

I am using Appery.io platform to build an app and ASP.NET to build a web page where the user can access his/her information.

I would like to use Appery.io backend services (file storage in this case) through the web page. So the user could upload his/her own images using the web site too, not only the app itself.

The problem is, all their sample code uses cURL and I don't know how to use cURL in an ASP.NET page.

I get this sample code from Appery.io platform:

curl -X GET \
     -H "X-Appery-Database-Id: 51840604e4b0446b3349ce64" \
     -G --data-urlencode 'username=<user_name>' \
    --data-urlencode 'password=<user_password>' \
     https://api.appery.io/rest/1/db/login

If there is no way of using direct cURL in ASP.NET, what options do I have?

PS: I don't have much experience with web developing

4

1 回答 1

3

我已经使用 javascrip 成功解决了这个问题。以防万一有人遇到同样的问题,我将发布一些代码示例。

//
// To use this Ajax call I had to add the jquery-1.8.2.js to the project.
// I created a Javascript.js file in my project and wrote this code.
//
function login(databaseId, userName, password) {
$.ajax({
    type: "GET",
    beforeSend: function (request) {
        request.setRequestHeader("X-Appery-Database-Id", databaseId);
    },
    url: "https://api.appery.io/rest/1/db/login",
    data: { username: userName, password: password },
    dataType: "json",
    success: function (response) {
        alert(JSON.stringify(response))
    },
    error: function (xhr, ajaxOptions, thrownError) {
        alert("Usuário ou senha incorretos.");
    }
});

}

然后我调用了 Silverlight 代码隐藏 MainPage.xaml.cs 文件中的 js 函数,使用按钮的单击事件。

private void btn_Click(object sender, RoutedEventArgs e)
{
    string DatabaseId = "99999999999999999999";
    string UserName = "user";
    string Password = "pass";

    HtmlPage.Window.Invoke("login", DatabaseId, UserName, Password);
}
于 2013-07-02T14:43:56.017 回答