I am trying to build a url using CGI input fields. One of the fields contain % as default value. Hence the url is being built as below:
$syscmd = "http://myserver:myport/reports/rwservlet?server=rptsvr+report=$REPORT";
$syscmd .= "+Xprocess=\"$in{'Xprocess'}\"";
The Xprocess variable contains % as default value and the url tunrs out to be something like below:
://myserver:myport/reports/rwservlet?server=rptsvr+report=apu_downtime_p+Xprocess=%
Now I am trying to traverse to that webpage and as % is not encoded to %25, I am facing with an error as shown below
REP-52006: The specified URL %22%%22 cannot be decoded.
Please help on how to encode % character in building the url.
Thank you.
You should use %25 for escaping %.
Here,
http://meyerweb.com/eric/tools/dencoder/
This can be useful in this case.
In your perl code, you could use URI::Encode (http://search.cpan.org/~mithun/URI-Encode-0.09/lib/URI/Encode.pm)
Related
I am writing a program to list all unique words in a movie subtitle file using Matlab. Now I have a unique word list that I want to translate to my language and learn the meaning before watching the movie.
Does anyone know how can I use Google Translate in Matlab so that I can complete my script? Is there any web service or so, and how can I use it in Matlab?
Thanks,
Appendix 1:
I have found this code useful:
%build url and send to google
url = 'http://ajax.googleapis.com/ajax/services/language/translate';
page = urlread(url, 'get', {'v', '1.0','q', inputString,'langpair', [sourceLanguage '|' destLanguage]});
but I don't know why it returns error each time I run it (e.g. 403 or 400). I know that my internet connection is okay when testing.
For a simple translator (I have no idea about quality), maybe try this. I didn't bother parsing the output:
langCodes = urlread('http://www.transltr.org/api/getlanguagesfortranslate'); % find your language code
textToTranslate = 'rabbit'; %change
langCodeOfOrigText ='en';
langCodeOfTranslation ='es';
translateURL = 'http://www.transltr.org/api/translate';
translateResults = urlread(translateURL, 'get', {'text',textToTranslate,'to',langCodeOfTranslation,'from',langCodeOfOrigText});
Just see next to translationText of the output for the result. Like I said, you can parse it, just google for a json to matlab struct parser.
I do have a filename from wikimedia commons and I want to access the thumbnail-image directly.
Example: Tour_Eiffel_Wikimedia_Commons.jpg
I found a way to get json-data containing the url to the thumbnail I want:
https://en.wikipedia.org/w/api.php?action=query&titles=Image:Tour_Eiffel_Wikimedia_Commons.jpg&prop=imageinfo&iiprop=url&iiurlwidth=200
but I don't want another request. Is there a way to access the thumbnail directly?
If you're okay to rely on the fact the current way of building the URL won't change in the future (which is not guaranteed), then you can do it.
The URL looks like this:
https://upload.wikimedia.org/wikipedia/commons/thumb/a/a8/Tour_Eiffel_Wikimedia_Commons.jpg/200px-Tour_Eiffel_Wikimedia_Commons.jpg
The first part is always the same: https://upload.wikimedia.org/wikipedia/commons/thumb
The second part is the first character of the MD5 hash of the file name. In this case, the MD5 hash of Tour_Eiffel_Wikimedia_Commons.jpg is a85d416ee427dfaee44b9248229a9cdd, so we get /a.
The third part is the first two characters of the MD5 hash from above: /a8.
The fourth part is the file name: /Tour_Eiffel_Wikimedia_Commons.jpg
The last part is the desired thumbnail width, and the file name again: /200px-Tour_Eiffel_Wikimedia_Commons.jpg
Solution in Python based on the solution of #svick:
import hashlib
def get_wc_thumb(image, width=300): # image = e.g. from Wikidata, width in pixels
image = image.replace(' ', '_') # need to replace spaces with underline
m = hashlib.md5()
m.update(image.encode('utf-8'))
d = m.hexdigest()
return "https://upload.wikimedia.org/wikipedia/commons/thumb/"+d[0]+'/'+d[0:2]+'/'+image+'/'+str(width)+'px-'+image
In case anyone is doing this query in SPARQL instead of Python:
There exists an MD5 function in SPARQL and the whole string manipulation can be implemented in SPARQL too!
BIND(REPLACE(wikibase:decodeUri(STR(?image)), "http://commons.wikimedia.org/wiki/Special:FilePath/", "") as ?fileName) .
BIND(REPLACE(?fileName, " ", "_") as ?safeFileName)
BIND(MD5(?safeFileName) as ?fileNameMD5) .
BIND(CONCAT("https://upload.wikimedia.org/wikipedia/commons/thumb/", SUBSTR(?fileNameMD5, 1, 1), "/", SUBSTR(?fileNameMD5, 1, 2), "/", ?safeFileName, "/650px-", ?safeFileName) as ?thumb)
Run this live query in Wikidata's query service: here, as discussed here: https://discourse-mediawiki.wmflabs.org/t/accessing-a-commons-thumbnail-via-wikidata/499
Following some good feedback on previous issue:
Gatling-tool Extracting cookie data
I have a post request in my gatling simulation which looks like the following:
.post("/checkout/onepage/form_key/${formkey}")
The variable ${formkey} is populated from a cookie value using:
.check(headerRegex("Set-Cookie","CACHED_FRONT_FORM_KEY=(.*)").saveAs("formkey"))
This appears to work correctly, however I now have an issue with:
java.net.URISyntaxException: Illegal character in path at index 90
Obviously I need to escape the special characters in the variable, but I'm unsure of how best to do this.
Gatling does provide a transform function:
https://github.com/excilys/gatling/wiki/Checks#wiki-transforming
I'm hoping I can use this to escape the characters. Any ideas would be greatly appreciated.
Yes, query paremeter parts must be URLEncoded.
In Gatling 1, transform takes a String and returns a String, so you would have something like:
.transform(rawCookieValue => java.net.URLEncoder.encode(rawCookieValue, "UTF-8"))
Im working on a script to hash a "fingerprint" for communicating with the secure Pay Direct Post API.
The issue I have is im trying to create a SHA-1 String that matches the sample code provided so that i can ensure things get posted accurately.
the example Sha-1 string appears encoded like
01a1edbb159aa01b99740508d79620251c2f871d
However my string when converted appears as
7871D5C9A366339DA848FC64CB32F6A9AD8FCADD
completely different...
my code for this is as follows..
<cfset variables.finger_print = "ABC0010|txnpassword|0|Test Reference|1.00|20110616221931">
<cfset variables.finger_print = hash(variables.finger_print,'SHA-1')>
<cfoutput>
#variables.finger_print#
</cfoutput>
Im using Coldfusion 8 to do this
it generates a 40 character hash, but i can see its generating completely different strings.
Hopefully someone out there has done this before and can point me in the right direction...
thanks in advance
** EDIT
The article for creating the Hash only contains the following information.
Example: Setting the fingerprint Fields joined with a | separator:
ABC0010|txnpassword|0|Test Reference|1.00|20110616221931
SHA1 the above string: 01a1edbb159aa01b99740508d79620251c2f871d
When generating the above example string using coldfusion hash it turns it into this
7871D5C9A366339DA848FC64CB32F6A9AD8FCADD
01a1edbb159aa01b99740508d79620251c2f871d
Sorry, but I do not see how the sample string could possibly produce that result given that php, CF and java all say otherwise. I suspect an error in the documentation. The one thing that stands out is the use of "txnpassword" instead of a sample value, like with the other fields. Perhaps they used a different value to produce the string and forgot to plug it into the actual example?
Update:
Example 5.2.1.12, on page 27, makes more sense. Ignoring case, the results from ColdFusion match exactly. I noticed the description also mentions something about a summarycode value, which is absent from the example in section 3.3.6. So that tends to support the theory of documentation error with the earlier example.
Code:
<cfset input = "ABC0010|mytxnpasswd|MyReference|1000|201105231545|1">
<cfoutput>#hash(input, "sha-1")#</cfoutput>
Result:
3F97240C9607E86F87C405AF340608828D331E10
I want to split a URL using the following code:
string url="http://images/newyork/1550/t_2911340.JPG";
file_name=server.MapPath("~/storedImages/")+"t_2911340.gif";
save_file_from_url(file_name,url);
But I want my code like this:
file_name=server.MapPath("~/storedImages/") +
( values after last / from url and before ) +
gif // by adding gif i want to rename it
Can you help me to split the code and append it?
Thanks in advance.
See the System.Uri class. Construct an instance of System.Uri, passing your URL string to the constructor. Then access the various properties of the Uri object as your "split" URL. To further split the path portion of the URL into segments, use the Segments Property.