dqwcdqs358367 2014-11-24 17:53
浏览 80

重写的URL导致406错误

I'm trying to create a RESTful API and document. However I seem to be getting a weird error I can't figure out how to fix.

This works:

curl --header "Accept: application/json" http://api.example.com/v1/method.php?key=test

However if you remove the ".php" extension and run this:

curl --header "Accept: application/json" http://api.example.com/v1/method?key=test

You should get a 406 error if you run it. Now if you drop the header that the curl is sending, both of the requests work just fine. However the documentation tool(swagger) I'm using requires it.

Here is my rewrite rule (found here):

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
  • 写回答

1条回答 默认 最新

  • dongmoxin7111 2014-11-24 17:57
    关注

    Try

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule method method.php [L]
    

    Your operation did not fail.

    Your backend service is saying that the response type it is returning is not provided in the Accept-Type HTTP header in your Client request.

    Ref: http://en.wikipedia.org/wiki/List_of_HTTP_header_fields

    • Find out the response (content type) returned by Service.
    • Provide this (content type) in your request Accept header.

    http://en.wikipedia.org/wiki/HTTP_status_code -> 406

    评论

报告相同问题?

悬赏问题

  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法