【问题标题】:How to write POST / PUT requests using RestFixture如何使用 RestFixture 编写 POST / PUT 请求
【发布时间】:2015-04-03 06:35:14
【问题描述】:

我正在尝试将 smartrics-RestFixture-3.0-bin.zip 用于 POST 请求,但由于某种原因它失败了。看起来像是服务问题本身,但在我学习 Fitnees 时,不确定测试是否有任何问题。

任何人都可以分享一些细节,或者使用演示 REST API 的 RestFixture/Wiki 格式的 POST 休息请求示例 - http://www.thomas-bayer.com/sqlrest/CUSTOMER/

我的基于 wiki 的 TC 如下所示 - (我正在尝试添加 ID = 20 的客户数据)

'''Trying to add customer 20 entry'''
!| smartrics.rest.fitnesse.fixture.FitRestFixture | http://www.thomas-bayer.com/sqlrest/CUSTOMER/ |
| setBody | <CUSTOMER xmlns:xlink="http://www.w3.org/1999/xlink"><ID>20</ID><FIRSTNAME>Anne1</FIRSTNAME><LASTNAME>Miller1</LASTNAME><STREET>201 Upland Pl.</STREET><CITY>Lyon1</CITY></CUSTOMER> |
| POST    | /20| 200 | | |

我低于错误:

<html><head><title>Apache Tomcat/7.0.26 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 500 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The server encountered an internal error () that prevented it from fulfilling this request.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/7.0.26</h3></body></html>

请提出建议。谢谢!

更新日期:2015 年 4 月 6 日

我试图使用不正确的 POST 方法添加新的 CUSTOMER 条目,我应该使用 PUT 方法。今天当我尝试使用 PUT 方法添加新的 CUSTOMER 条目时,我得到了同样的错误:(..

看起来只有 WEB 服务有问题。

【问题讨论】:

    标签: api rest post fitnesse fitnesse-slim


    【解决方案1】:

    服务是否正常工作,如果您以其他方式向它发送相同的正文,您会得到不同的响应吗? (当我将您的正文发送到相同的 url 时,我会收到相同的错误。)

    该错误似乎表明您调用的服务已损坏。有时这也可能是错误使用的结果。

    就目前而言,您的问题似乎与 FitNesse 的关系不大,而与您正在使用的服务有关。

    【讨论】:

    • 感谢 Fried 的回复。我也认为该服务有一些问题..不确定,因为它是一项公共服务并且真的不知道它的状态。您认为 Table 或 Test 的编写方式是否正确?想知道测试/数据或其创建方式是否有问题?请评论。谢谢!
    • 测试表及其结构看起来没问题,因为请求正确地到达了服务器。通过将 setBody 的内容包含在 !- -! 中来重试! : |setBody| !-
    • 表看起来还不错。我尝试发送相同的正文(使用我自己的夹具参见github.com/fhoeben/hsac-fitnesse-fixtures/wiki/…)并得到相同的响应
    • 我必须使用 PUT 将新条目添加到数据库中而不是 POST 吗?
    • @smartrics 如果我尝试用 !- -!然后我得到 - “客户端发送的请求在语法上不正确()”并且没有封闭我得到与问题中提到的相同 - “服务器遇到内部错误()阻止它完成这个请求。”
    【解决方案2】:

    在我将 setHeaders 部分添加到我的 wiki 之前,我遇到了同样的错误。 在 setBody 之后试试这个:

    | setHeaders|Content-Type: application/xml|

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-25
      • 1970-01-01
      • 2013-07-04
      • 1970-01-01
      • 1970-01-01
      • 2012-01-21
      • 1970-01-01
      相关资源
      最近更新 更多