url-parsing

Error Domain=NSURLErrorDomain Code=-1004 instead of -1009 in Swift service calls

↘锁芯ラ 提交于 2019-12-23 02:38:12
问题 Generally, while performing GET or POST calls in iOS using dataTaskWithRequest or sendAsynchronousRequest we use to face network related errors with error codes like, NSURLErrorNotConnectedToInternet = -1009 NSURLErrorCannotConnectToHost = -1004 NSURLErrorTimedOut = -1001 In my case i'm disconnecting the internet and performing service calls. So, the expected error code is "NSURLErrorNotConnectedToInternet = -1009" . But, its throwing "NSURLErrorCannotConnectToHost = -1004" like below, Error

How to identify the top level domain of a URL object using java?

半城伤御伤魂 提交于 2019-12-22 05:14:48
问题 Given this : URL u=new URL("someURL"); How do i identify the top level domain of the URL.. 回答1: So you want to have the top-level domain part only? //parameter urlString: a String //returns: a String representing the TLD of urlString, or null iff urlString is malformed private String getTldString(String urlString) { URL url = null; String tldString = null; try { url = new URL(urlString); String[] domainNameParts = url.getHost().split("\\."); tldString = domainNameParts[domainNameParts.length

Get page URL parameters from a service worker

假如想象 提交于 2019-12-22 00:26:38
问题 How do I get page URL with parameters from a service worker? I have tried self.registration.scope but that doesn't include the parameters. 回答1: I'm not clear as to whether you're asking about getting the service worker script's URL, or the URLs of all of the client pages that are open under the service worker's scope. So... here's how to do both: // Get a URL object for the service worker script's location. const swScriptUrl = new URL(self.location); // Get URL objects for each client's

Reconstructing absolute urls from relative urls on a page

前提是你 提交于 2019-12-18 12:48:12
问题 Given an absolute url of a page, and a relative link found within that page, would there be a way to a) definitively reconstruct or b) best-effort reconstruct the absolute url of the relative link? In my case, I'm reading an html file from a given url using beautiful soup, stripping out all the img tag sources, and trying to construct a list of absolute urls to the page images. My Python function so far looks like: function get_image_url(page_url,image_src): from urlparse import urlparse #

URL parsing in Java

别来无恙 提交于 2019-12-18 06:18:05
问题 I've got the URL like this: http://test.com/testapp/test.do?test_id=1&test_name=SS Is there any way we can get only this part /test.do?test_id=1&test_name=SS 回答1: Use java.net.URL to parse a url string: URL url = new URL("http://test.com/testapp/test.do?test_id=1&test_name=SS"); System.out.println(url.getPath()+"?"+url.getQuery()); 回答2: Inside your ActionClass String actionName = (String)ActionContext.getContext().get(ActionContext.ACTION_NAME); will give you "test". HttpServletRequest

Break a URL into its components

独自空忆成欢 提交于 2019-12-18 03:23:41
问题 I'm using javascript and would like to take a URL string that I have and break it down into its components such as the host, path, and query arguments. I need to do this in order to get to one of the query arguments, which is itself a URL and is thus encoded in the original URL string. I feel like there should be an easy way to do this in Javascript. Perhaps something that looks like this: var what_I_Want = url("http://www.domain.com?queryArg1=somequeryargument").getQueryArgumentValue(

How to get the last path in a URL?

江枫思渺然 提交于 2019-12-17 17:42:22
问题 I would like get the last path segment in a URL: http://blabla/bla/wce/news.php or http://blabla/blablabla/dut2a/news.php For example, in these two URLs, I want to get the path segment: 'wce', and 'dut2a'. I tried to use $_SERVER['REQUEST_URI'] , but I get the whole URL path. 回答1: Try: $url = 'http://blabla/blablabla/dut2a/news.php'; $tokens = explode('/', $url); echo $tokens[sizeof($tokens)-2]; Assuming $tokens has at least 2 elements. 回答2: Try this: function getLastPathSegment($url) { $path

Regex ignore URL already in HTML tags

南楼画角 提交于 2019-12-17 14:52:41
问题 I'm having a little problem with my Regex I've made a custom BBcode for my website, however I also want URLs to be parsed too. I'm using preg_replace and this is the pattern used to identify URLS: /([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/])/is Which works great, however if a URL is within a [img][/img] block, the above pattern also picks it up and produces a result like this: //[img]http://url.com/toimg.jeg[/img] will produce this result: <img src="<a href="http://url.com/toimg.jeg" target="_blank"

Change URL parameters

拜拜、爱过 提交于 2019-12-16 19:57:03
问题 I have this URL: site.fwx?position=1&archiveid=5000&columns=5&rows=20&sorting=ModifiedTimeAsc what I need is to be able to change the 'rows' url param value to something i specify, lets say 10. And if the 'rows' doesn't exist, I need to add it to the end of the url and add the value i've already specified (10). 回答1: I've extended Sujoy's code to make up a function. /** * http://stackoverflow.com/a/10997390/11236 */ function updateURLParameter(url, param, paramVal){ var newAdditionalURL = "";

Parsing a list into a url string

孤街浪徒 提交于 2019-12-13 01:57:16
问题 I have a list of tags that I would like to add to a url string, separated by commas ('%2C'). How can I do this ? I was trying : >>> tags_list ['tag1', ' tag2'] >>> parse_string = "http://www.google.pl/search?q=%s&restofurl" % (lambda x: "%s," %x for x in tags_list) but received a generator : >>> parse_string 'http://<generator object <genexpr> at 0x02751F58>' Also do I need to change commas to %2C ? I need it to feedpaarser to parse results. If yes - how can I insert those tags separated by