0

您好我一直在尝试将字段发布到客户端提供的 Web 服务。客户给了我具体的文件等以使用为例。

我是 web 服务的新手,但我敢打赌,我很接近……这里的结果是客户希望我发送的。

以下是一些使用 cURL 的示例/文档:

$ curl --data '{"firstname": "William S.", "lastname": "Walker", "language": "EN", "city": "Ottawa", "state": "ON", "country": "CA", "telephone": "613-737-5719", "mobilephone": "613-737-5719", "fax": "613-737-5719", "email": "WilliamSWalker@rhyta.com", "entreprise": "Helping Hand", "passtype": "None", "passwordchanged": false, "professionalactivity": "Respiratory care practitioner", "registrationdate": "2010-04-20T20:08:21", "sectorofinterest": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam quis nisl vestibulum, egestas enim vel, egestas erat. Aenean sodales ipsum tortor, ut facilisis elit fermentum eget.", "webpage": "http://www.GolfCleaners.com", "workplace": "Helping Hand"}' -X POST -H 'Authorization: Token token="token"' https://link.mobile.test.com/api/v1/conferences/4/participants

我试图使用 ajax 发送并发布到这个函数。这是我的ajax

函数 addAttendee(){

$.ajax({
    url: "https://link.mobile.test.com/api/v1/conferences/4/participants",
    type: "POST",

    dataType: "html",
    data: "firstname=Kevin&lastname=Gauthier&telephone=4502605353&email=kevin@konige.com&token=7f5cebd3b6c62559f53d1179571e10da",
    contentType: "application/json; charset=utf-8",
    success: function(data) {
        // handle your successful response here
    },
    error: function(xhr, ajaxOptions, thrownError) {
        // handle your fail response here
    }
});
}

我不明白的是,这将返回那个HTTP 令牌:访问被拒绝。
有人可以帮助我现在很困惑。

也许这只是我,我不明白网络服务的概念。

提前致谢

4

1 回答 1

1

这是我今天刚刚用于在 Jquery 中发布数据的示例 AJAX 调用。

 $.ajax({
        type: "POST",
        url: "/feedbacks.json",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        data: JSON.stringify({ category: "categoryType", message_text: "messageString", anonymous: "anonymous_user" ,other_information: "otherInfo", browser_name: "browser_info", ssm_version: "ssmVersion"}),
        success: function () {
            window.close();
        },
        error: function(model, response) {
            var errMsg = "Your feedback could not be submitted."
            window.appEvents.trigger(UIEvents.app.failure, errMsg, 'modal')
        }
    });
于 2013-10-22T18:48:34.967 回答