-2
我的问题是,我的控制器像GET一样处理POST方法。当我尝试将参数传递给post方法时,它给了我GET结果,因为它们具有相同的语法。POST请求被认为是GET
我的POST功能如下:
/**
* @ApiDoc(description="Uploads photo with tags.")
*
* @Rest\FileParam(name="image", image=true, description="Image to upload.")
* @Rest\RequestParam(name="tags", requirements=".+", nullable=true, map=true, description="Tags that associates photo.")
* @Rest\View()
*/
public function postPhotoAction(ParamFetcher $paramFetcher, array $tags)
{
$em = $this->getDoctrine()->getManager();
$photo = new Photo();
$form = $this->createForm(new PhotoType, $photo);
if ($tags) {
$tags = $em->getRepository('TestTaskTagsBundle:Tag')->findOrCreateByTitles($tags);
}
$form->submit($paramFetcher->all());
if (!$form->isValid()) {
return $form->getErrors();
}
foreach ($tags as $tag) {
$photo->addTag($tag);
}
$em->persist($photo);
$em->flush();
return array('photo' => $photo);
}
当我尝试发布使用这个网址的图片:http://localhost/test/web/app_dev.php/photos?tags[]=bebe&_format=json&image=E:\photos\n3ass.jpg
,它让我得到结果。 如何解决这个问题?
所以没有办法添加的参数在网址发布请求? – Nada
没有 http://stackoverflow.com/questions/14551194/how-are-parameters-sent-in-an-http-post-request –
好吧,我会尽量使用hurl.it – Nada