Tag: URL 方案

对已修改的base64 URL进行解码/编码的代码

我想base64编码数据把它放在一个URL,然后解码它在我的HttpHandler。 我发现Base64编码允许一个'/'字符,这将弄乱我的UriTemplate匹配。 然后我发现wikipedia有一个“修改过的Base64 for URL”的概念: 存在用于URL变体的修改的Base64,其中将不使用填充“=”,并且将标准Base64的“+”和“/”字符分别replace为“ – ”和“_”,以便使用URL编码器/解码器不再是必需的,并且对编码值的长度没有影响,使得相同的编码forms保持原样用于关系数据库,网页表格和对象标识符。 使用.NET我想修改我现在的代码从做基本的base64编码和解码到使用“修改后的base64 for URL”方法。 有没有人做过这个? 为了解码,我知道它开始与像这样的东西: string base64EncodedText = base64UrlEncodedText.Replace('-', '+').Replace('_', '/'); // Append '=' char(s) if necessary – how best to do this? // My normal base64 decoding now uses encodedText 但是,我需要添加一个或两个'='字符到最后看起来更复杂一点。 我的编码逻辑应该更简单一些: // Perform normal base64 encoding byte[] encodedBytes = Encoding.UTF8.GetBytes(unencodedText); string base64EncodedText = Convert.ToBase64String(encodedBytes); // […]

更改url并使用jQueryredirect

我有这样的代码, <form id="abc"> <input type="text" id="txt" /> </form> 现在我想这样redirect, var temp = $("#txt").val(); url = "http:abc.com/" + temp; window.location.replace(url); or window.location(url); 有没有在jQuery中解决这个问题? 它仍然让我有url = http://abc.com 。

如何使用Android上的cookie发出http请求?

我想在正确处理cookie(例如存储服务器发送的cookie,并在发出后续请求时发送这些cookie)的同时向远程服务器发出http请求。 这将是很好的保存任何和所有的cookie,但真正的唯一我关心的是会话cookie。 在java.net中,看起来这样做的首选方法是使用java.net.CookieHandler(抽象基类)和java.net.CookieManager(具体实现)。 Android有java.net.CookieHandler,但是它似乎没有java.net.CookieManager。 我可以通过检查http头来手工编码,但似乎必须有一个更简单的方法。 在保留cookie的同时在Android上进行http请求的正确方法是什么?

从URL获取文件名

在Java中,给定一个java.net.URL或http://www.example.com/some/path/to/a/file.xmlforms的String ,获取文件名最简单的方法是什么,减去扩展名? 所以,在这个例子中,我正在寻找返回"file"东西。 我可以想到几种方法来做到这一点,但我正在寻找一些容易阅读和简短的东西。

获取UIWebView的当前url

我已经尝试使用: webview.request.URL获取我的UIWebView的当前url。 不幸的是, NSURL是空的。 这里有什么问题吗? 我正在使用Xcode 3.2.2 beta 5。 上面的代码应该在UIWebView委托didStartLoad执行。

从ASP.NET MVC控制器redirect到外部URI

我试图从一个操作方法redirect到外部url,但无法让它工作。 有谁可以澄清我的错误? public void ID(string id) { string url = string.Empty; switch (id) { case "DB2FCB11-579F-4DA2-A68C-A6495B9BAAB5": url = "http://www.somesite.com"; break; } Response.Redirect(url, true); } 谢谢,克里斯

URLEncoder无法翻译空格字符

我期待 System.out.println(java.net.URLEncoder.encode("Hello World", "UTF-8")); 输出: Hello%20World (20是空格的ASCIIhex代码) 但是,我得到的是: Hello+World 我使用错误的方法吗? 什么是我应该使用的正确的方法?

首选的Java方法来ping HTTP URL的可用性

我需要一个监视器类来定期检查给定的HTTP URL是否可用。 我可以使用Spring TaskExecutor抽象来关心“常规”部分,所以这不是主题。 问题是: 在java中ping一个URL的首选方法是什么? 这是我现在的代码作为一个起点: try { final URLConnection connection = new URL(url).openConnection(); connection.connect(); LOG.info("Service " + url + " available, yeah!"); available = true; } catch (final MalformedURLException e) { throw new IllegalStateException("Bad URL: " + url, e); } catch (final IOException e) { LOG.info("Service " + url + " unavailable, oh […]

如何在NGINX中redirect一个url

我需要将每个http://test.com请求redirect到http://www.test.com 。 如何才能做到这一点。 在服务器块,我尝试添加 rewrite ^/(.*) http://www.test.com/$1 permanent; 但在浏览器中说 The page isn't redirecting properly Firefox has detected that the server is redirecting the request for this address in a way that will never complete. 我的服务器块看起来像 server { listen 80; server_name test.com; client_max_body_size 10M; client_body_buffer_size 128k; root /home/test/test/public; passenger_enabled on; rails_env production; #rewrite ^/(.*) http://www.test.com/$1 permanent; […]

Python Flask如何从URL中获取参数?

在Flask中,我如何从URL中提取参数? 我怎样才能使用瓶和python从URL提取命名参数? 当用户访问在我的烧瓶应用程序上运行的这个URL时,我希望Web服务能够处理问号后指定的参数: http://10.1.1.1:5000/login?username=alex&password=pw1 #I just want to be able to manipulate the parameters @app.route('/login', methods=['GET', 'POST']) def login(): username = request.form['username'] print(username) password = request.form['password'] print(password)