Hello all,
As in the subject line : I've got a relative URL path with arguments it
which I need to have its special chars escaped so it can be used in a HTTP GET line. (example: "/some+part/another+part?arg1=foo+42%23brown&arg2=bar+fly"). The thing is that I can't seem to find an API function for it.
The ShlwApi UrlEscape function doesn't even seem to want to touch the arguments on a full URL, and the WinInet InternetCreateUrl function does not want to function with only the path and arguments parts being provided.
Looking at what docs.microsoft.com says about them does not show any leads either.
In other words, does someone know which function I'm supposed to use to create an escaped relative URL with arguments ?
Or am I supposed to (again) just roll my own ...
Maybe I'm different in that I've been writing string parsing
code for decades, but for me it's much faster to roll my own
than go through all the stuff you've described above (and you
still haven't found a solution yet).
Don't be afraid to do your own parsing. It's often simpler than
figuring out how to use some proprietary API.
And it's actually kind of fun once you get into it.
Besides, you might want your program to run on a Linux box someday...
In other words, does someone know which function I'm supposed to use to create an escaped relative URL with arguments ?
I think it would be helpful if you gave an example of the output
you wanted
and the input you have.
It sounds like you're looking looking for InternetCombineUrlA
(with an empty lpszBaseUrl)
Tavis,
I think it would be helpful if you gave an example of the output
you wanted
Blimey, I thought I did : [quote]example: "/some+part/another+part?arg1=foo+42%23brown&arg2=bar+fly"[/quote]
and the input you have.
I think you misunderstood : I do not have some specific input, I need random inputs to be correctly (combined and) escaped into a valid, relative URLs with arguments.
It sounds like you're looking looking for InternetCombineUrlA
(with an empty lpszBaseUrl)
I saw it but ignored it as I assumed it would just combine. But no, it ecapes too. Alas, it has the same flaw UrlEscape has : it ignores
everything after the (first) question mark.
Ohhh... Interresting - Using InternetCombineUrlA :
Input: "/some#part/other stuff?arg=my cat# a fragment"
Output: "/some?arg=my cat# a fragment#part/other stuff"
Notice that the part from the first hash upto the questionmark (*not* the following slash) is moved to the end of the string. Ofcourse, now that that moved part is right of the questionmark its not escaped either.
[1] Currently I can't even seem to find if a space char must be percent-escaped or should become a "+" character. The mentioned functions do the former, FF here does the latter ...
The "+" space escaped character is dependent on the server script.
i.e. not every server (script) support the "+" space escaped character.
Sure, but the point was it wasn't clear if that is what you *want* or
what you *have*.
Umm.. I think that's obvious :)
What I don't understand is why you can't show what specific input
you have that should produce the specific output above?
It's helpful that you showed the input you have, but again, it
would be helpful if you show the output you *wanted* too :)
Input: "/some#part/other stuff?arg=my cat# a fragment"
Output: "/some?arg=my cat# a fragment#part/other stuff"
Is the URL already cracked, i.e. you know which part is a fragment
and a query?
It's helpful that you showed the input you have, but again, it
would be helpful if you show the output you *wanted* too :)
Thats the wrong question.
Its not about what *I* want, but what the rules (whatever they are) decree
it should look like - so it can be broken up by the webserver into the exact same parts as provided by the client program.
I was asking those questions for a reason. Imagine that you had
the string "/foo/bar?a=x#z", you could encode this a bunch of
different ways.
For example, if you got this URL from a user, then it needs to
be cracked first
The only solution I see is to provide the path, argument and fragment
as seperate strings, so that all three can be encoded /before/ gluing
them together (using their respective delimiters).
I think I've run out of patience for this, sorry!
In other words, does someone know which function I'm supposed to use to create an escaped relative URL with arguments ?
Or am I supposed to (again) just roll my own ...
The ShlwApi UrlEscape function doesn't even seem to want to touch the arguments on a full URL
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 379 |
Nodes: | 16 (2 / 14) |
Uptime: | 42:01:53 |
Calls: | 8,141 |
Calls today: | 4 |
Files: | 13,085 |
Messages: | 5,857,792 |