给定一个url和一个查询字符串,如何获取查询字符串与url组合产生的url?
我正在寻找类似于.htaccess的功能qsa.我意识到完全手工实现这是相当简单的,但有没有内置函数处理查询字符串,可以简化或完全解决这个问题?
输入/结果集示例:
Url="http://www.example.com/index.php/page?a=1"
QS ="?b=2"
Result="http://www.example.com/index.php/page?a=1&b=2"
Run Code Online (Sandbox Code Playgroud)
-
Url="page.php"
QS ="?b=2"
Result="page.php?b=2"
Run Code Online (Sandbox Code Playgroud) 如果我用没有参数值的查询字符串设计我的 REST API,你能想到什么缺点?像这样:
http://host/path/to/page?edit
http://host/path/to/page?delete
http://host/path/to/page/+commentId?reply
Run Code Online (Sandbox Code Playgroud)
而不是例如:
http://host/api/edit?page=path/to/page
http://host/api/delete?page=path/to/page
http://host/api/reply?page=path/to/page&comment=commentId
Run Code Online (Sandbox Code Playgroud)
(编辑:任何page-X?edit和page-X?delete链接将触发 GET 请求,但不会实际编辑或删除页面。相反,它们显示一个页面<form>,其中page-X可以编辑,或者显示<form>一个真正删除页面-X?确认对话框。该实际编辑/删除请求将POST或DELETE请求。在相同的方式host/api/edit?page=path/to/page显示与编辑页面<form>。/编辑。)
请注意,这?action不是查询字符串通常的格式。相反,它们的格式通常如下:?key=value;key2=v2;key3=v3
此外,有时我会使用这样的 URL:
http://host/path/to/page?delete;user=spammer
Run Code Online (Sandbox Code Playgroud)
也就是说,我将包含一个没有值 ( delete)的查询字符串参数和一个具有值 ( user=spammer) 的参数(为了删除垃圾邮件发送者发布的所有评论)
我的 Web 框架可以很好地处理像?reply. 所以我想我最想知道的是,你能想到任何客户端问题吗?或者有什么问题,我应该决定使用另一个 Web 框架吗?(您知道您使用的框架是否提供有关没有参数值的查询字符串的信息吗?)
(我通过阅读http://labs.apache.org/webarch/uri/rfc/rfc3986.html 的理解是,我使用的查询字符串格式很好,但这对所有客户端和服务器框架有什么影响。)
(我目前使用 Lift-Web 框架。我也测试了 Play Framework,并且可以获取无值的查询字符串参数,所以从我的角度来看,Play 和 Lift-Web 似乎都不错。)
这是一个关于没有值的查询字符串的相关问题。但是,它处理null在某些情况下返回的 ASP.NET 函数:Access Query string …
我想发送一个 ajax 请求,但我试图构建的查询字符串是空的。
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>This is a project to show how to use RESTful</title>
</head>
<body>
<script type="text/javascript">var contexPath = "<%=request.getContextPath()%>";</script>
<script src="<%=request.getContextPath()%>/js/jquery.js"></script>
<script type="text/javascript">
function doAjaxPost() {
var queryString = $('#htmlform') // empty
alert("doAjaxPost Called:" + queryString + ":");
$.ajax({
...
...
});
}? </script>
<H1>Add Employee</H1>
<p>
<form name="htmlform">
<table border=1>
<thead><tr>
<th>ID</th>
<th>Name</th>
<th>Email</th>
</tr></thead>
<tr>
<td><input type="text" name="ID" maxlength="5" size="3"></td>
<td><input type="text" name="Name" maxlength="10" size="10"></td>
<td><input type="text" name="Email" maxlength="10" size="10"></td>
</tr>
</table> …Run Code Online (Sandbox Code Playgroud) 有人可以解释在URL中传递不同参数的重要性,
例如
1: www.domain.com/folder1/folder2/file.html?param=9?val=ty5?test
2: www.domain.com/folder1/folder2/file.html#param=93#val=t5y5?test=9
3: www.domain.com/folder1/folder2/file.html¶m=9?val=ty5&test=90#poiu
Run Code Online (Sandbox Code Playgroud)
基本上我想知道这三个字符(#, &, ?)在网址中做了什么.我大部分时间都见过他们?我可以使用除此之外的其他东西,例如:www.domain.com/folder1/folder2/file.html*param=9_val+ty5@test
在 PHP 中重新加载页面的最佳方法是什么?从 URL 中删除所有以前的查询字符串值?
简单的问题,但我不知道该怎么做。我有一个带有 GridView 的页面,它最初填充了一个查询字符串。
获得查询字符串值后,我不需要查询字符串,因为我使用 DropDownList 的值来填充 GridView。
我怎样才能摆脱它?
回发不会清除它,它只是继续标记。
我试过 Request.QueryString.Clear,但得到“只读”错误。
我将不胜感激您在解决此问题时能给我的任何帮助。
编辑 1
using System;
using System.Configuration;
using System.Data;
using System.Data.Odbc;
using System.Globalization;
using System.Threading;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Reflection;
public partial class GV : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
my_DDL();
GridViewBind();
}
}
protected void my_DDL()
{
.......
}
protected void DDL_SelectedIndexChanged(object sender, EventArgs e)
{
PropertyInfo Isreadonly = typeof(System.Collections.Specialized.NameValueCollection).GetProperty("IsReadOnly", BindingFlags.Instance | BindingFlags.NonPublic);
Isreadonly.SetValue(Request.QueryString, false, null);
Request.QueryString.Clear();
}
public DataTable …Run Code Online (Sandbox Code Playgroud) 我正在寻找一个现有的解决方案来序列化记录来查询字符串,但一无所获.我知道F#的漂亮打印,但我不知道如何手动访问它.
通常我想要这样的东西:
type Person = {first:string; last:string}
type Group = {name:string; size:int}
let person = {first="Mary"; last="Smith"}
let personQueryString = Something.toQueryString person
let group = {name="Full"; size=345}
let groupQueryString = Something.toQueryString group
Run Code Online (Sandbox Code Playgroud)
哪里
personQueryString -> "first=Mary&last=Smith"
groupQueryString -> "name=Full&size=345"
Run Code Online (Sandbox Code Playgroud) 我想从Twig页面发送query_string URL中的参数并将其放入控制器中.
例如: index.html.twig
<a href="/newcont/add/{{ id }}">New</a>
Run Code Online (Sandbox Code Playgroud)
并且controller:
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
class Newcont extends Controller
{
/**
* @Route("/newcont/add/{id}", requirements={"id": "\d+"})
*/
public function addAction(Request $request){
$params = $request->request->all();
//$id = $request->query->get();
var_dump($params);
die;
}
}
Run Code Online (Sandbox Code Playgroud)
我希望有一个带有twig变量的url,该变量被发送到控制器动作.
我有基于 WebApi 的 Web 服务,例如:
public class ControllerName : ApiController
{
[Route("api/ControllerName/{p1}/{p2}/{p3}/{p4}/{p5}")]
public string GetItemByNameAndId(string p1, string p2, string p3, string p4, string p5)
{
}
}
Run Code Online (Sandbox Code Playgroud)
这种类型的请求正在工作:
主机/api/ControllerName/1/2/3/4/5
但我想要这种类型的请求:
主机/api/控制器名称/&p1=1&p2=2&p3=3&p4=4&p5=5
我收到如下错误:
从客户端 (&) 检测到潜在危险的 Request.Path 值。必须遵循哪些步骤?配置文件中的任何更改、任何属性等。
谢谢你的时间。
嗨,我需要使用查询参数构造 url 请求,我有一个带有键和值的嵌套对象,如下所示
"user": {
"first_name": "Srini",
"last_name": "Raman",
"gender": "male",
"dob": "1992-08-02",
"address_attributes": {
"city": "San Diego",
"state": "CA",
"zip": 92127,
"country": "USA",
"latitude": 37.257009,
"longitude": -120.050767
}
}
Run Code Online (Sandbox Code Playgroud)
我需要获得一个查询参数,如
user[first_name]=Srini&user[last_name]=Raman&user[address_attributes][city]=San Diego&user[address_attributes][state]=CA
Run Code Online (Sandbox Code Playgroud) query-string ×10
url ×3
c# ×2
javascript ×2
php ×2
.net ×1
anchor ×1
api ×1
asp.net ×1
f# ×1
http ×1
jquery ×1
parameters ×1
postback ×1
qsa ×1
rest ×1
routing ×1
symfony ×1
url-routing ×1