一个数字字符串作为数组键在PHP中(A numeric string as array key in PHP)
使用数字字符串(
"123"
作为PHP数组中的键,而不转换为整数?$blah = array('123' => 1); var_dump($blah);
版画
array(1) { [123]=> int(1) }
我想要
array(1) { ["123"]=> int(1) }
Is it possible to use a numeric string like
"123"
as a key in a PHP array, without it being converted to an integer?$blah = array('123' => 1); var_dump($blah);
prints
array(1) { [123]=> int(1) }
I want
array(1) { ["123"]=> int(1) }
原文:https://stackoverflow.com/questions/4100488
更新时间:2023-03-30 11:03
最满意答案
当您登录网站时,可能会设置一个授权会话cookie,需要在后续请求中发送以维护会话。
你可以得到这样的cookie:
Connection.Response res = Jsoup.connect("http://www.example.com/login.php") .data("username", "myUsername", "password", "myPassword") .method(Method.POST) .execute(); Document doc = res.parse(); String sessionId = res.cookie("SESSIONID"); // you will need to check what the right cookie name is
然后发送下一个请求,如:
Document doc2 = Jsoup.connect("http://www.example.com/otherPage") .cookie("SESSIONID", sessionId) .get();
When you login to the site, it is probably setting an authorised session cookie that needs to be sent on subsequent requests to maintain the session.
You can get the cookie like this:
Connection.Response res = Jsoup.connect("http://www.example.com/login.php") .data("username", "myUsername", "password", "myPassword") .method(Method.POST) .execute(); Document doc = res.parse(); String sessionId = res.cookie("SESSIONID"); // you will need to check what the right cookie name is
And then send it on the next request like:
Document doc2 = Jsoup.connect("http://www.example.com/otherPage") .cookie("SESSIONID", sessionId) .get();
相关问答
更多-
userAgent让服务器感觉访问者更像一个真实的浏览器在访问,cookie是看服务器需不需要,timeout还需要解释吗,你不设置有一个默认的超时时间
-
jsoup发帖和cookie(jsoup posting and cookie)[2022-01-15]
当您登录网站时,可能会设置一个授权会话cookie,需要在后续请求中发送以维护会话。 你可以得到这样的cookie: Connection.Response res = Jsoup.connect("http://www.example.com/login.php") .data("username", "myUsername", "password", "myPassword") .method(Method.POST) .execute(); Document doc = re ... -
你的代码给了我 HTTP error fetching URL. Status=404, URL=https://www.rbauction.com/home/auth& 如果您只更改: .data("_58_redirect", "%2Fhome%2Fauth&")的.data("_58_redirect", "%2Fhome%2Fauth") (没有尾随的&符号) 它工作正常! 如果没有,请检查您的用户/通行证。 Your code gives me HTTP error fetching URL. ...
-
cookie(name, value)期望cookie的名称不是其相关的url。 试试这个: doc = Jsoup // .connect("https://need.authentication.com") // .header("Cookie", cookie) // .get(); cookie(name, value) expects the name of the cookie not its related url. Try this instead ...
-
您确定要使用cookie检索验证码吗? 请检查一下。 我的意思是,您可以下载验证码,例如: Response res1 = Jsoup.connect("https://academics.vit.ac.in/parent/captcha.asp") .cookie("ASPSESSIONIDSQHDAQRQ", sessionid) .ignoreContentType(true) .method(Method.GET).t ...
-
jsoup发布Java(jsoup posting Java)[2024-02-16]
这是我的代码: URL form = new URL(Your_url); connection1 = (HttpURLConnection)form.openConnection(); connection1.setRequestProperty("Cookie", your_cookie); connection1.setReadTimeout(10000); StringBuilder whole = new StringBuilder(); BufferedReader in = new Buf ... -
JSoup登录和Cookie(JSoup Login and Cookie)[2023-09-20]
我在表单中缺少Login参数。 在包括之后我能够获得一个好的cookie。 I was missing the Login parameter in the form. After including that I was able to get a good cookie back. -
获取使用jsoup登录网站后创建的会话ID cookie(Get session id cookie which is created after login to website with jsoup)[2023-08-08]
最后我找到了解决方案: 你可以通过使用Connection.Method.POST一步完成。 所以响应是POST的响应 Connection.Response loginForm = Jsoup.connect(LOGIN_URL) .userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0") .method(Connection.M ... -
我好像我已经解决了这个问题。 我在发布之前就看到了这个问题,并认为这是我的解决方案。 但是,当我尝试添加代码以忽略页面上的搜索按钮时,没有任何改变。 我再次查看了我的代码只是为了看到我拼错了搜索按钮的ID ... I seems i have solved it by myself. I saw this question right before posting this and thought it was my solution. However when i tried to add code to ...
-
经过多次调试后,我资助了问题的根源和奇怪的行为。 cookies / headers / url没有问题,问题出在.method() 。 .method()的默认值是Method.GET 。 但由于我发送动态请求,我还必须动态构建它。 为此,我正在解析表单以获取方法,然后添加连接构造中所需的类型。 if (method.equals("post")) { return Method.POST; } if (method.equals("get")) { ...