Mechanical Turk拒绝POST请求

时间:2013-08-20 01:56:23

标签: java rest mechanicalturk

我正在尝试使用MTurk restful API,并使用HITTypeID对POST进行创建,但是,我收到以下错误:

<?xml version="1.0"?>
<CreateHITResponse>
  <OperationRequest>
    <RequestId>199c9aff-86a4-4280-8d2f-d956a53515b0</RequestId>
  </OperationRequest>
  <HIT>
    <Request>
      <IsValid>False</IsValid>
      <Errors>
        <Error>
          <Code>AWS.MissingParameters</Code>
          <Message>Your request is missing required parameters. Required parameters include Question. Question is a required parameter. (1376962818123)</Message>
          <Data>
            <Key>Parameter</Key>
            <Value>Question</Value>
          </Data>
          <Data>
            <Key>Description</Key>
           <Value>Question is a required parameter</Value>
          </Data>
          <Data>
            <Key>Description</Key>
            <Value>Question is a required parameter</Value>
          </Data>
          <Data>
            <Key>Parameter</Key>
            <Value>Question</Value>
          </Data>
        </Error>
      </Errors>
    </Request>
  </HIT>
</CreateHITResponse>

根据我的理解,如果给出Hittype,则不需要标题。所以看起来API实际上并没有查看POST主体。

我将如何解决这个问题?我的请求有什么问题吗?

请求:

<CreateHITRequest>
  <HITTypeId>HITTYPEID</HITTypeId>
  <MaxAssignments>1</MaxAssignments>
  <LifetimeInSeconds>604800</LifetimeInSeconds>
  <Question>&lt;QuestionForm Structure&gt;</Question>
</CreateHITRequest>

2 个答案:

答案 0 :(得分:5)

您不能通过REST将XML发布到Mechanical Turk。看起来你把REST和SOAP混为一谈。

Mechanical Turk的REST接口仅采用URL编码的键值对like this

https://mechanicalturk.amazonaws.com/?Service=AWSMechanicalTurkRequester
&AWSAccessKeyId=[the Requester's Access Key ID]
&Version=2012-03-25
&Operation=CreateHIT
&Signature=[signature for this request]
&Timestamp=[your system's local time]
&HITTypeId=T100CN9P324W00EXAMPLE
&Question=[URL-encoded question data]
&LifetimeInSeconds=604800

答案 1 :(得分:1)

我混淆了POST请求参数。 对于MTURK REST API,您不是POST XML结构,而是标头+值到指定的URL。

您可以在POST正文中将它们作为params发布,而不是URL params。

例如下面的GET请求:

GET https://mechanicalturk.amazonaws.com/?Service=AWSMechanicalTurkRequester &AWSAccessKeyId=[the Requester's Access Key ID] &Version=2012-03-25 &Operation=CreateHIT &Signature=[signature for this request] &Timestamp=[your system's local time] &HITTypeId=T100CN9P324W00EXAMPLE &Question=[URL-encoded question data] &LifetimeInSeconds=604800

会变成:

POST https://mechanicalturk.amazonaws.com/?Service=AWSMechanicalTurkRequester AWSAccessKeyId=[the Requester's Access Key ID] &Version=2012-03-25 &Operation=CreateHIT &Signature=[signature for this request] &Timestamp=[your system's local time] &HITTypeId=T100CN9P324W00EXAMPLE &Question=[URL-encoded question data] &LifetimeInSeconds=604800

URL下面的所有内容都是POST正文。

希望这有助于某人。