如果您查看Stackoverflow.com的源代码,您会看到对其css文件的引用是:
<link href="/Content/all.min.css?v=2383" rel="stylesheet" type="text/css" />
Run Code Online (Sandbox Code Playgroud)
这是如何完成的,以便他们可以通过查询字符串传递一个版本并提供正确的CSS文件?
我试图在Java中创建一个简单的HttpServer来处理GET请求,但是当我尝试获取请求的GET参数时,我注意到HttpExchange类没有方法.
有没有人知道一种简单的方法来读取GET参数(查询字符串)?
这是我的处理程序的样子:
public class TestHandler{
@Override
public void handle(HttpExchange exc) throws IOxception {
String response = "This is the reponse";
exc.sendResponseHeaders(200, response.length());
// need GET params here
OutputStream os = exc.getResponseBody();
os.write(response.getBytes());
os.close();
}
}
Run Code Online (Sandbox Code Playgroud)
..和主要方法:
public static void main(String[] args) throws Exception{
// create server on port 8000
InetSocketAddress address = new InetSocketAddress(8000);
HttpServer server = new HttpServer.create(address, 0);
// bind handler
server.createContext("/highscore", new TestHandler());
server.setExecutor(null);
server.start();
}
Run Code Online (Sandbox Code Playgroud) 假设我有一个实用函数,为了简单起见(真实的东西很复杂且无关紧要),返回当前窗口的查询字符串.
var someUtilityFunction = () {
return window.location.search.substring(1);
};
Run Code Online (Sandbox Code Playgroud)
现在我想在qUnit中对这个函数进行单元测试(不确定测试工具是否相关):
test('#1 someUtilityFunction works', function () {
// setup
var oldQS = window.location.search;
window.location.search = '?key1=value1&key2=value2&key3=value3';
var expectedOutput = 'key1=value1&key2=value2&key3=value3';
// test
equals(someUtilityFunction(),
expectedOutput,
'someUtilityFunction works as expected.');
// teardown
window.location.search = oldQS;
});
Run Code Online (Sandbox Code Playgroud)
这里的问题是设置window.location.search为不同的查询字符串会导致页面重新加载,实质上是进入无限的请求循环.有没有办法模拟window.location对象而不对someUtilityFunction函数进行任何更改?
我希望能够区分现有的查询字符串参数设置为null和缺少参数.所以问题的部分是:
谢谢
模型绑定是否也通过查询字符串工作?
如果我有一个获取请求,例如:
GET /Country/CheckName?Country.Name=abc&Country.Id=0 HTTP/1.1
Run Code Online (Sandbox Code Playgroud)
CountryController中的以下方法是否具有包含Id和Name属性的oCountry参数以及查询字符串中的值?
public ViewResult CheckCountryName(Country oCountry)
{
//some code
return View(oCountry);
}
Run Code Online (Sandbox Code Playgroud)
出于某种原因,我在OCountry对象中将Id称为0并将Name作为null.缺什么 ?
我需要使用 Next.js 创建以下 API 端点:
/api/products/[name]?keyword=${anykeyword}。
我知道我需要在index.js 中的pages/api/products/[name] 目录中创建它。但我怎样才能访问keyword.
req.query仅包含name.
以下是我的代码:
import { connectToDatabase } from "../../../../util/mongodb";
import validate from "../../../../validation/product";
//capitalize first letter only to avoid errors
import capitalize from "lodash.capitalize";
export default async function productsHandler(req, res) {
const {
query: { name, keyword }, // here i cannot access keyword//
method,
} = req,
Name = capitalize(name),
{ db } = await connectToDatabase(),
searchCriteria = keyword ? keyword : "price";
switch (method) …Run Code Online (Sandbox Code Playgroud) 我该怎么用:
等等
URI表示具有1个名称的Person资源,但我需要在逻辑上将第一个与最后一个分开以识别每个.我有点像最后一个例子,因为我能做到:
我只是试图让jquery识别一个段落的第一个字母.我该怎么做?
例如,我有一个页面上有一些paragrahs页面.我希望只有以指定字母开头的段落才能被赋予"当前"类,而其他所有段都被隐藏.我非常知道如何添加类并隐藏其他类,但是,我不能让jquery识别第一个字母.
其次,是否可以从url字符串中提取这个"第一个字母"变量?
例如,第1页 - 有一个字母列表.用户点击"B",网址为
http://domain.com/page2.html?letter=b
并且page2获取该变量(b)并将其应用于Jquery,仅显示那些段落
假设我有一个网址,例如:
http://www.example.com/hello.png?w=100&h=100&bg=white
Run Code Online (Sandbox Code Playgroud)
我想要做的是更新w和h查询字符串的值,但保持bg查询字符串不变,例如:
http://www.example.com/hello.png?w=200&h=200&bg=white
Run Code Online (Sandbox Code Playgroud)
那么什么是读取查询字符串值的最快最有效的方法(它们可以是任何一组查询字符串值,而不仅仅是w,h和bg),更新一些值或不更新值,并返回完整的URL与新的请求参数?
所以:
所以这可能需要很长时间,但我完全不知道可能导致此问题的原因:
我正在提供客户端JavaScript,它解析嵌入它的页面上的某些参数,使用这些参数构建URL并使用该URL将iframe注入页面,如:
var queryParams = {
param: 'foo'
, other: 'bar'
};
Run Code Online (Sandbox Code Playgroud)
变成了:
<iframe src="http://example.net/iframes/123?param=foo&other=bar"></iframe>
Run Code Online (Sandbox Code Playgroud)
这工作得很好,我每天提供大约150万个请求.然而,我最近注意到,在每天大约3.000个案例中,查询参数的值被洗牌,所以这样请求:
<iframe src="http://example.net/iframes/123?param=ofo&other=rba"></iframe>
Run Code Online (Sandbox Code Playgroud)
从日志来看,这与特定用户有关,并且每个请求都会重新发生字符的混乱,因此当用户使用脚本浏览具有多个页面的站点时,我可以看到这样的序列:
108.161.183.122 - - [14/Sep/2015:15:18:51 +0000] "GET /iframe/ogequl093iwsfr8n?param=3a1bc2 HTTP/1.0" 401 11601 "http://www.example.net/gallery?page=1" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0"
108.161.183.122 - - [14/Sep/2015:15:19:07 +0000] "GET /iframe/ogequl093iwsfr8n?param=a21b3c HTTP/1.0" 401 11601 "http://www.example.net/gallery?page=2" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0"
108.161.183.122 - - [14/Sep/2015:15:19:29 +0000] "GET /iframe/ogequl093iwsfr8n?param=ba132c HTTP/1.0" 401 11601 "http://www.example.net/gallery?page=3" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0"
Run Code Online (Sandbox Code Playgroud)
401正在服务器期望的故意发生param=abc123.
我还注意到大多数错误都发生在Firefox和Safari中,而Google …
query-string ×10
javascript ×5
asp.net-mvc ×2
jquery ×2
.net ×1
c# ×1
css ×1
firefox ×1
get ×1
html ×1
httpserver ×1
java ×1
next.js ×1
php ×1
qunit ×1
reactjs ×1
request ×1
rest ×1
safari ×1
unit-testing ×1
uri ×1
url ×1