te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - Is using a query string in POST request a bad practice? - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Is using a query string in POST request a bad practice? - Stack Overflow

programmeradmin4浏览0评论

There is a system that sends POST requests from frontend to backend. These POST requests do not use the body to pass the data to the server; instead, it uses query strings in the URL params.

These requests do not send files or JSON, only several string params.

W3C does not describe that situation .html

Is it a bad practice to use query strings for POST requests, and if there any negative consequences of using that from security or performance or architecture reasons?

Are there any conventions that define the usage of body or query strings for different types of requests?

There is a system that sends POST requests from frontend to backend. These POST requests do not use the body to pass the data to the server; instead, it uses query strings in the URL params.

These requests do not send files or JSON, only several string params.

W3C does not describe that situation https://www.w3/Protocols/rfc2616/rfc2616-sec9.html

Is it a bad practice to use query strings for POST requests, and if there any negative consequences of using that from security or performance or architecture reasons?

Are there any conventions that define the usage of body or query strings for different types of requests?

Share Improve this question asked Sep 24, 2020 at 8:40 Alex BorodinAlex Borodin 2,0341 gold badge15 silver badges30 bronze badges 2
  • 1 You can refer to this question – Jerson Commented Sep 24, 2020 at 8:45
  • similar: stackoverflow./q/611906 – djvg Commented Oct 24, 2023 at 14:08
Add a ment  | 

2 Answers 2

Reset to default 7

Reminder: In 2014, RFC2616 was replaced by multiple RFCs (7230-7237).

Is using a query string in POST request a bad practice?

Not if you know what you are doing.

Mechanically, it is all fine: are we allowed to use POST with a target-uri that includes a query-part? Yes. Are we allowed to use POST with an empty request body? Yes. Are we allowed to do both of those things at the same time? Yes.

The hard part: will this POST request invalidate the correct representations from the cache?

Cache-invalidation happens when the server returns a non-error response to an unsafe request (POST is an unsafe request method). The representations that are invalidated are those that match the target-uri of the unsafe request.

GET /foo?a=b HTTP/2.0
POST /foo?a=b HTTP/2.0

Here, if the POST is successful, the representations cached after the successful GET request will be invalidated in the cache.

GET /foo HTTP/2.0
POST /foo?a=b HTTP/2.0

Here, the effective request-uri is not the same, which means that general purpose ponents won't invalidate the cached representations of /foo.

There's nothing wrong with using query parameters in a URL in a POST request, with or without a request body. If it makes semantic sense for your request, it's fine. The POST method in itself has a semantic meaning distinct from GET, it doesn't require a request body to be useful, and the URL is yet distinct from that again. A classic example might be:

POST /foo/bar?token=83q2fn2093c8jm203

I.e., passing some sort of token through the URL.

There's no general security problem here, since anyone who could intercept this POST request to read the URL could also read its body data; you'll hardly find an attacker in a position that allows them to read the URL but not the body. However, URLs are typically logged in server access logs and browser histories, while request bodies aren't; that may or may not be worth considering, depending on what information you're transporting in those parameters and who has access to those logs.

发布评论

评论列表(0)

  1. 暂无评论