How to encode the URL in the Http Get method.

Hi, I need to encode a url in the Http get method, I found URLEncodedPostData but that is used send message request can someone help me with this?

Hi RexDoug,

private String encodeUrl(String hsURL) {
        URLEncodedPostData urlEncoder = new URLEncodedPostData("UTF-8" , false);
        urlEncoder.setData(hsURL);
        hsURL = urlEncoder.toString();
        System.out.println(hsURL);
        return hsURL;
}

I tried thisbut it don't work I need to encode the url http get method.

I used this code where I mention rules in URLEncodedPostData it works for me in coded form url in the get method.

public String encodeUrl(String s){
        if (s!=null) {
            StringBuffer tmp = new StringBuffer();
            int i=0;
            try {
                while (true) {
                    int b = (int)s.charAt(i++);
                    if ((b>=0x30 && b<=0x39) || (b>=0x41 && b<=0x5A) || (b>=0x61 && b<=0x7A) ||(b == 0x2F) || (b == 0x3A) || (b == 0x2D )|| (b == 0x2E)|| (b == 0x2C)|| (b == 0x3F)|| (b == 0x3D) ||(b == 0x26) || (b == 0x5F) || (b == 0x2A)) {
                        tmp.append((char)b);
                    }
                    else {
                        tmp.append("%");
                        if (b <= 0xf) tmp.append("0");
                        tmp.append(Integer.toHexString(b));
                    }
                }
            }
            catch (Exception e) {}
            return tmp.toString();
        }
        return null;
}

Tags: BlackBerry Developers

Similar Questions

  • HTTP GET method with the body of the message

    Hi all

    I work with an API using HTTP to make calls to a server. I met an API call in the documetnation that uses the HTTP GET method with a message body. It seems that this is not supported by LV14 because I do not see an entry of message body for the LabVIEWHTTPClient.lvlib:GET.vi function. The POST methods and COULD appear to be banned for this API call, I a not found 405. I could be stuck with the help of GET.

    Certainly, this isn't recommended GET method - but it is not explicitly forbidden in the HTTP/1.1 specification. Is there a work around to submit an HTTP GET request to content? I have to use HTTP external DLL to achieve?

    All entries would be great.

    Thank you

    Richard

    Seems to be a problem on the server side?  Maybe I misunderstood what you were trying to get?

  • How to load the CMOS (get the Bios settings) on Lenovo IdeaCentre K330

    Hello

    How to load the CMOS (get the Bios settings) on Lenovo IdeaCentre K330? Found no parameters. I can click on F2, then network and passwords, is this all I could configure?

    OK, I got it - you must click F1 several times when starting system upward!

  • How to set the http and SOCKS proxy

    Hello guys im using this code
    String data = URLEncoder.encode("formName", "UTF-8") + "=" + URLEncoder.encode("formName is true", "UTF-8");
    It works but if I use the http or socks proxy proxy that does not work.
    is it possible to solve this kind of problem?

    Published by: EJP on 26/07/2011-10:49: fixed your misleading title. URLEncoder is completely unrelated to this issue, as several posters have noted.

    Published by: jhovarie on August 19, 2011 23:35

    As opposed to OK?

  • How to encode the string in base64 format

    Hello

    I need to encode variable QString in base64 format.   I am new to this technology. Could someone please tell me how should I do this?

    https://developer.BlackBerry.com/native/reference/Cascades/QString.html#toUtf8 returns a QByteArray

    or https://developer.blackberry.com/native/reference/cascades/qbytearray.html#append-2 adds a QString to a QByteArray

  • How to reset the short authentication method?

    Hi, I use short under Windows 3.1 and my portal just short had the admin user ([email protected]) created.

    I badly changed the authentication method for ID instead of email (which is the default) and now when I try to log in with admin, it gives a message that the user is not valid...

    Is it possible to reset the default authentication method?

    Thank you

    Ygor

    For the default user "admin" is the username screen, not the user ID. That's why you could not open a session using "admin".

    The user ID is a number.

    I don't know the exact structure of the Studio database, but would it be possible for user you to get the user ID for the user admin off the table so that you can log in and change the setting back?

    Unless you have opened a Studio session, I don't know how you could change the setting.

  • How to stop the tab 'Getting started with Mozilla Firefox' to open every time I open FF?

    Everytime I open FF, the tab "Getting started with Mozilla Firefox" opens. I checked and it is not in my list of homepage.

    If I open any additional windows, it does not open.

    But, once I close all the and reopen it again, the tab opens.

    I had a similar problem with some addons (ietab) do the same thing.

    I found the fix for it.

    About: config, filter for 'Start '

    Ones you want to should appear at the bottom.

    Startup.homepage_override_url and startup.homepage_welcome_url

    Double-click on each one and delete the text string. Close and reopen the window to check that it worked.

    As I deleted them both at the same time, I'm not sure who was the culprit. So, I suggest starting by striking first and tests before deleting this one.

  • How to use the LMSGetValue javascript method?

    I try to call the javascript LMSGetValue method when loading the first slide in my class.

    However, the following does not work:

    studentName = LMSGetValue ("cmi.core.student_name");

    I have consulted with technical support from the LMS, and they said, it seems as if captivate does not define the LMSGetValue method in the js file included in the course.

    I have to do something to include the file scormdriver.js in the course, when it is published?

    Any help would be appreciated.

    SCORM_CallLMSGetValue ("CMI. Core.student_name");

    You can also call this function once you get the name if it is not in the correct order:

    ReverseNameSequence (strName)

  • OSX Apache Server: how to redirect the http request?

    Hi all

    I have a Mini Mac OSX Server El Capitan running. It already serves some sites. Normal Server Web sites:

    -site1.example.com

    -site2.example.com

    Now, I have installed an application that has its own built-in web server. This application would be normally accessible via http on port 80. However, http on port 80 connections are automatically considered trapped by integrated apache of the OSX Server. Therefore, I now put the web application to run in a different port to apache. I also setup a subdomain, so that users can access this application directly, but they also have to type in the port in the URL - for example, the new web app site is reachable at the:

    -myapp.example.com:7117

    What I would do, is for users to simply access the application using:

    -monappli.exemple.com

    I know that there is a way for us to have apache to "Reroute" all requests for a specific to an internal port subdomain automatically, but I don't even know where to start. What are the files we need to configure on OSX Server? How configure us them?

    Any guidance would be greatly appreciated.

    I had the same requirement and has resolved the way you want to as described below.

    1. Define the additional app to run on another port
    2. Create a site in.app using port 80 and the same host name you want to use for the additional application
    3. Set up a redirection for this site in.app as follows
    4. Source = /, Destination = http://hostname.domain.com:1234 /, Status = Permanent (301)

    Of course, use the correct host name, the domain and port for your situation.

    PS. the same approach I have described above also can be used to redirect the corresponding https port 80 or 443 site.

  • How to pass the parameters in the http post method?

    Hello

    I want to download the mp3 file on server and I need to pass two parameters with the post method.

    Here is my code for this.

                          String userid="id_user=8379";
                  String filename="trackName=sample.mp3";
                  String params=userid+"&"+filename;            
    
                            httpcon=(HttpConnection)Connector.open("http://api.upload.com/gStorage/uploadSong?output=json",Connector.READ_WRITE);
                httpcon.setRequestMethod(HttpConnection.POST);
                httpcon.setRequestProperty("Content-type","application/x-www-form-urlencoded");
                httpcon.setRequestProperty("Content-type","audio/mpeg3");
                os=httpcon.openOutputStream();
                os.write(params.getBytes("UTF-8"));
                fc=(FileConnection)Connector.open("file:///E:/sample.mp3",Connector.READ_WRITE);
                fileis=fc.openInputStream();
                bos=new ByteArrayOutputStream();
                byte[] data=new byte[50000];
                int ch;
                while ((ch=fileis.read(data,0,data.length))!=-1) {
                    bos.write(data,0,ch);
                }
                os.write(bos.toByteArray());
                os.close();
                System.out.println("Response code From server"+httpcon.getResponseCode());
                if(httpcon.getResponseCode()!=HttpConnection.HTTP_OK)
                {
                    System.out.println("Failed to upload bytes");
                }
                else
                {
                    //is=httpcon.openInputStream();
                    DataInputStream dis=httpcon.openDataInputStream();
                    int ch1;
                    StringBuffer buffer1=new StringBuffer();
                    while ((ch1=dis.read())!=-1) {
                        buffer1.append((char)ch1);
                    }
                    System.out.println("Response From Server"+buffer1.toString());
                }
            } i am getting response code ok but fail to upload file.
    

    may I passing the parameter in the wrong way?

    thankx.

    Hello

    Nitin I currently do a midlet project.

    So I used multipart post method.

    I just read this article. http://MindTouch.firmstep.com/AchieveForms/Design_Guide/Integration_Actions/types/HTTP_POST#top

    package com.http.main;
    
    import java.io.ByteArrayOutputStream;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.util.Enumeration;
    import java.util.Hashtable;
    
    import javax.microedition.io.Connector;
    import javax.microedition.io.HttpConnection;
    
    import com.sun.midp.io.BufferedConnectionAdapter;
    
    public class HttpMultipartRequest
    {
        static final String BOUNDARY = "----------V2ymHFg03ehbqgZCaKO6jy";
    
        byte[] postBytes = null;
        String url = null;
    
        public HttpMultipartRequest(String url, Hashtable params, String fileField, String fileName, String fileType, byte[] fileBytes) throws Exception
        {
            this.url = url;
    
            String boundary = getBoundaryString();
    
            String boundaryMessage = getBoundaryMessage(boundary, params, fileField, fileName, fileType);
    
            String endBoundary = "\r\n--" + boundary + "--\r\n";
    
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
    
            bos.write(boundaryMessage.getBytes());
    
            bos.write(fileBytes);
    
            bos.write(endBoundary.getBytes());
    
            this.postBytes = bos.toByteArray();
    
            bos.close();
        }
    
        String getBoundaryString()
        {
            return BOUNDARY;
        }
    
        String getBoundaryMessage(String boundary, Hashtable params, String fileField, String fileName, String fileType)
        {
            StringBuffer res = new StringBuffer("--").append(boundary).append("\r\n");
    
            Enumeration keys = params.keys();
    
            while(keys.hasMoreElements())
            {
                String key = (String)keys.nextElement();
                String value = (String)params.get(key);
    
                res.append("Content-Disposition: form-data; name=\"").append(key).append("\"\r\n")
                    .append("\r\n").append(value).append("\r\n")
                    .append("--").append(boundary).append("\r\n");
                System.out.println("****In while Loop:-****"+res);
            }
            res.append("Content-Disposition: form-data; name=\"").append(fileField).append("\"; filename=\"").append(fileName).append("\"\r\n")
                .append("Content-Type: ").append(fileType).append("\r\n\r\n");
            return res.toString();
        }
    
        public byte[] send() throws Exception
        {
            HttpConnection hc = null;
    
            InputStream is = null;
    
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
    
            byte[] res = null;
    
            try
            {
                hc = (HttpConnection) Connector.open(url);
    
                hc.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + getBoundaryString());
                hc.setRequestProperty("Content-Length",postBytes+"");
    
                hc.setRequestMethod(HttpConnection.POST);
    
                OutputStream dout = hc.openOutputStream();
    
                dout.write(postBytes);
                dout.close();
    
                int ch;
    
                is = hc.openInputStream();
                StringBuffer buffer=new StringBuffer();
    
                while ((ch = is.read()) != -1)
                {
                    bos.write(ch);
                    buffer.append((char)ch);
                }
                res = bos.toByteArray();
                System.out.println(buffer.toString());
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
            finally
            {
                try
                {
                    if(bos != null)
                        bos.close();
    
                    if(is != null)
                        is.close();
    
                    if(hc != null)
                        hc.close();
                }
                catch(Exception e2)
                {
                    e2.printStackTrace();
                }
            }
            return res;
        }
    }
    

    and use it in this way

    public void getBytes()
        {
            ByteArrayOutputStream bos=null;
            try
            {
                bos=new ByteArrayOutputStream();
                InputStream fis=getClass().getResourceAsStream("/super.mp3");
                int ch;
                byte[] data=new byte[120];
                while((ch=fis.read(data,0,data.length))!=-1)
                {
                    bos.write(data,0,data.length);
                }
                Hashtable params=new Hashtable();
                //params.put("id_user","8474");
                params.put("id_user","8379");
                params.put("file1","audio.mp3");
                HttpMultipartRequest httpreq=new HttpMultipartRequest("http://api.upload.com/gStorage/uploadSong?", params,"file1","xpressMusic.mp3","audio/mpeg",bos.toByteArray());
                httpreq.send();
                bos.close();
                fis.close();
            }
            catch (Exception e) {
                System.out.println("Exception"+e);
            }
    

    Here, the key is contenttype, contentLength.you can get the info on it from the link above.

    thankx.

  • How to encode the string in a string?

    Hello:
    How to use a string in a string? See the example below. It gives me an error.

    IMMEDIATELY EXECUTE "DELETE FROM EMPLOYEE WHERE EMP_NAME = 20153-01";

    894324 wrote:
    Hello:
    How to use a string in a string? See the example below. It gives me an error.

    IMMEDIATELY EXECUTE "DELETE FROM EMPLOYEE WHERE EMP_NAME = 20153-01";

    http://kerryosborne.Oracle-guy.com/2009/08/quotes-in-strings-Oracle-q-quote/

  • How to change the HTTPS Console Weblogic admin port

    Hello


    I want to change my HTTPS Console port which was default port 7799 to other ports and also weblogic admin port 7101 to another port.
    How we change that. Thank you


    Thank you
    Sachin Bhadauria

    you need to change the powers of oversight for the EMGC_GCDomain reflect the new administration server port.
    Go to the target-> Middleware-> EMGC_Domain
    Select Configuration of the target-> supervision of the identification information in the drop farm
    Change the Port field
    Return to the menu drop-down firm and select Refresh WebLogic Domain-> Add targets to update
    The objectives of OHS and Server Admin should now appear in the console. I checked on my test site.

  • How to publish the http live stream

    When I use Adobe Flash Media Server 4.5 publish live http streams. I found a message from Server Log to manage Adobe Flash Media Console administrator servers. It is said that 'Impossible to record the live stream (disk quota exceeded)."  How can I do to resolve the issue?

    Hello

    Thank you for using the FMS 4.5.

    I assume you are using a developer edition (trail), FMS. It has restriction of 10 minutes for HDS streaming, after which, the journal exceeded disk Quota would come to the top. You must upgrade to the other flavors use HDS full-time.

  • QT: How to access the HTTPS Web site?

    There are specialized libraries necessary to deploy to access websites https with QNetwork and Playbook?

    I always have error 6.

    Others also have problems with this?

    Have you tried to connect the signal of SSLErrors and see what error? If the error is not important, you can tell Qt to ignore the SSL error

    check this: http://doc.qt.nokia.com/4.7-snapshot/qnetworkaccessmanager.html#sslErrors

  • How to receive the http on the BlackBerry itself as a server request

    Hi all

    I make a request which I must do a http called through SOAP web services and wish to receive this request http to my Blackberry itself (suppose that, by default, port). that is, I use the BlackBerry device as a client and the server.

    Please suggest me if RIM provides APIs of java application server server or someone has an idea about this.

    I use devic BB: BB 8900 OS v5.0

    Thanks in advance!

    Hello ashutoshg,

    Unfortunately the best I can give is that localhost and 127.0.0.1 simply don't are not supported with regard to a BlackBerry network connection.

    The following forum thread discusses two methods of obtaining the IP address of your device when it is connected via WiFi and I saw the success of these approaches in the past:

    http://supportforums.BlackBerry.com/T5/Java-development/WiFi-IP-address/TD-p/374272

    The only thing to note is that this kind of HTTP communication will travel through the WiFi network and back to the equipment; rather than work around the network via the loopback address infrastructure.

    Erik Oros

    BlackBerry Development Advisor

Maybe you are looking for