in reply to HTTP::Request::Common - Unescape some characters

":" in a value must be escaped. You're asking us to help you generate invalid urls. What's the real problem?

Update: Or maybe not. It's conditional:

If data for a URI component would conflict with a reserved character's purpose as a delimiter, then the conflicting data must be percent-encoded before the URI is formed.

It's still valid to escape it, though, and most clients will. You can't even trust proxies to preserve it.

  • Comment on Re: HTTP::Request::Common - Unescape some characters

Replies are listed 'Best First'.
Re^2: HTTP::Request::Common - Unescape some characters
by ejaincom (Novice) on Jun 27, 2009 at 10:35 UTC
    Hi,
    Ok let me give you an example for the string:
    The original string is:
    http://api.url?data=<?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE MESSAGE SYSTEM "http:// +127.0.0.1/psms/dtd/message.dtd" ><MESSAGE><USER USERNAME="test" PASSW +ORD="XXXXXX"/><SMS UDH="0" CODING="1" TEXT="The flight # <101> "DEL" +to "BLR" is delayed and it's revised time will be informed later. Hav +e a nice day!" PROPERTY="0" ID="1"><ADDRESS FROM="ValueFirst" TO="91X +XXXXXXXXX" SEQ="1" TAG="some clientside random data" /></SMS></MESSAG +E>&action=send

    The escaped string is:
    http://api.url/psms/servlet/psms.Eservice2?data=%3C?xml%20version=%221 +.0%22%20encoding=%22ISO-8859-1%22?%3E%3C!DOCTYPE%20MESSAGE%20SYSTEM%2 +0%22http://127.0.0.1/psms/dtd/message.dtd%22%20%3E%3CMESSAGE%3E%3CUSE +R%20USERNAME=%22test%22%20PASSWORD=%22valueone%22/%3E%3CSMS%20%20UDH= +%220%22%20CODING=%221%22%20TEXT=%22The%20flight%20No.%20SG101:%20DEL% +20to%20BLR%20is%20delayed%20and%20it's%20revised%20time%20will%20be%2 +0informed%20later.%20Have%20a%20nice%20day!%22%20PROPERTY=%220%22%20I +D=%221%22%3E%3CADDRESS%20FROM=%22ValueFirst%22%20TO=%22919891153528%2 +2%20SEQ=%221%22%20TAG=%22some%20clientside%20random%20data%22%20/%3E% +3C/SMS%3E%3C/MESSAGE%3E&action=send

    Pl. let me know how to generate the escaped string:
    Please help me as this is getting crucial for me
    Thanks
    abhi

      That's very long for a URL. Most serves have a limit on the length of the URLs they can handle.

      Also, your XML is invalid. You have unescaped double quotes in a double quoted attributes value, and "<" is not allowed to appear in attribute values. You need to use "&quot;" and "&lt;". Parsers might excuse the latter, but the former will definitely result in an error.

      TEXT="The flight # <101> "DEL" to "BLR" is ..."
      should be
      TEXT="The flight # &lt;101> &quot;DEL&quot; to &quot;BLR&quot; is ..."

      But to answer your question, you can use URI to build a URL (a kind of URI).

      use URI qw( ); chomp( my $data = <<'__EOI__' ); <?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE MESSAGE SYSTEM "h +ttp://127.0.0.1/psms/dtd/message.dtd" ><MESSAGE><USER USERNAME="test" + PASSWORD="XXXXXX"/><SMS UDH="0" CODING="1" TEXT="The flight # <101> +"DEL" to "BLR" is delayed and it's revised time will be informed late +r. Have a nice day!" PROPERTY="0" ID="1"><ADDRESS FROM="ValueFirst" T +O="91XXXXXXXXXX" SEQ="1" TAG="some clientside random data" /></SMS></ +MESSAGE> __EOI__ my $url = URI->new('http://api.url/psms/servlet/psms.Eservice2'); $url->query_form( data => $data, action => 'send', ); print "$url\n";
      #!/usr/bin/perl -- use strict; use warnings; use HTTP::Request::Common; use URI; { my $uri = URI->new('http://localhost/'); print POST( $uri, ['data' => '<data>'])->as_string; $uri->query_form('data' => '<data>'); print GET( $uri )->as_string; } __END__ POST http://localhost/ Content-Length: 15 Content-Type: application/x-www-form-urlencoded data=%3Cdata%3E GET http://localhost/?data=%3Cdata%3E