If I encode a string like this:
var escapedString = originalString.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)
it doesn't escape the slashes /
.
I've searched and found this Objective C code:
NSString *encodedString = (NSString *)CFURLCreateStringByAddingPercentEscapes( NULL, (CFStringRef)unencodedString, NULL, (CFStringRef)@"!*'();:@&=+$,/?%#[]", kCFStringEncodingUTF8 );
Is there an easier way to encode an URL and if not, how do I write this in Swift?
I have a dict like this:
d = {'orderBy': 'XXXXX'}
When I call urlencode (), it transforms into:
orderBy = XXXXX
But I needed it to look like this:
orderBy = "XXXXX"
Does anyone know how I add these two quotes using urllib?Thank you!
I have a strange problem. I have in the past used a program I wrote myself to check if a new chapter has come out on a story at fanfiction.net and that program works fine even now (though its GUI leaves a lot to wish for).
However, when I am trying to make a new version I can't seem to load the webpage even though I'm using the exact same code (Copy Pasted). This is the code below. When sending in a URL like https://www.fanfiction.net/s/11012678/36 to the nextExists method it should return 'true'. My old program does, but this one doesn't even though it's the same code.
The only thing I can think of that might have any effect would be that I am using a new version of Eclipse which might cause it to mistake the Encoding, but I have tried checking all the common encoding types and nothing provides the HTML plaintext.
Does anyone have any idea what might be causing this? It's not a disaster if I can't get this right but I would like to know for the future in case I run into the same problem again.
import java.io.BufferedReader;import java.io.InputStreamReader;import java.net.URL;public class Util { private static final String BEFORE = "<button class=btn TYPE=BUTTON onClick=\"self.location='", AFTER = "'\">Next ></button>", SITE = "fanfiction.net"; public static String readSite(String path) throws Exception{ URL url = new URL(path); BufferedReader in = null; String line; try{ StringBuilder builder = new StringBuilder(); in = new BufferedReader(new InputStreamReader(url.openStream())); line = in.readLine(); if(line == null){ return null; } builder.append(line); while((line = in.readLine()) != null){ builder.append('\n' + line); } return builder.toString(); } finally{ if(in != null){ in.close(); } } } public static String updatePathToEnd(String path) throws Exception{ outer: while(nextExists(path)){ String data = readSite(path); if(path.contains(SITE)){ String link = path.substring(0, path.indexOf(SITE) + SITE.length()) + data.substring(data.indexOf(BEFORE) + BEFORE.length(), data.indexOf(AFTER)); if(readSite(link) != null) { path = link; continue outer; } } } return path; } public static boolean nextExists(String path) throws Exception{ String text = readSite(path); if(path.contains(SITE)){ return text==null ? false : text.contains(AFTER); } return false; }}
We are using Jersey Client 2.21. I am noticing that when we put curly braces (aka curly brackets) as a param value, then it does not get properly encoded. Not only that, but anything inside the curly braces does not get encoded either. This is not true for regular brackets or other unsafe characters that I have tested with.
Please see the example below. In this example I enter three params. A control param with just spaces. One with curly braces, and one with regular brackets.
public static void testJerseyEncoding() { Client client = ClientBuilder.newClient(); String url = "http://foo.com/path"; Map<String, String> map = new HashMap<>(); map.put("paramWithCurly", " {with a space}"); map.put("paramWithOutCurly", "with a space"); map.put("paramWithBracket", "[with a space]"); WebTarget target = client.target(url); for (Map.Entry<String, String> entry : map.entrySet()) { target = target.queryParam(entry.getKey(), entry.getValue()); } System.out.println(target.toString());}
Here is the output:
JerseyWebTarget { http://foo.com/path?paramWithBracket=%5Bwith+a+space%5D¶mWithOutCurly=with+a+space¶mWithCurly=+{with a space} }
Is something broken with the Jersey Client or am I missing something? The curly braces should have been encoded to "%7B".
I am trying to write a windows client application that calls a web site for data. To keep the install to a minimum I am trying only use dlls in the .NET Framework Client Profile. Trouble is that I need to UrlEncode some parameters, is there an easy way to do this without importing System.Web.dll which is not part of the Client Pofile?
บ้าน - แผนผังเว็บไซต์ - ความเป็นส่วนตัว - ลิงค์ - Copyright © 2019 Cortex IT Ltd : ติดต่อ : admin @ cortexit.co.uk
Please note that by viewing our site you agree to our use of cookies (see ความเป็นส่วนตัว for details). You will only see this message once.