URL max lenght

77 views
Skip to first unread message

Jovo Mirkovic

unread,
Oct 17, 2013, 10:35:58 AM10/17/13
to codenameone...@googlegroups.com
Is there any limit on the URL length in CN1?
I have a long URL (with image, Base64 converted), and I want call web service and put it in database.
 
When is image enough small, everything is OK, but when is image bigger, I get Error message 414: Request - URl to long.
 
If I put that URL directly to browser, everything is OK... That is reason why I think that is not problem on web server...
 
Thanks,
     Jovo
 
@Override
    protected void onMain_MultiButtonAction(Component c, ActionEvent event) {
        Capture.capturePhoto(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                try {
                    if (evt == null) {
                        return;
                    }
                    String path = (String) evt.getSource();
                    if (ImageIO.getImageIO() != null) {
                                           
                        Image img = Image.createImage(path);
                       
                        InputStream i = FileSystemStorage.getInstance().openInputStream(path);
                        byte[] b = Util.readInputStream(i);                                               
                        String slika;                          
                        slika = com.codename1.util.Base64.encode(b);                     
                        findLblSlika1().setIcon(img);
                        findLblSlika1().setText(slika.toString());                       
                    }
                } catch (Exception ex) {
                    Log.e(ex);
                }
            }
        });
    }
    @Override
    protected void onMain_ButtonAction(Component c, ActionEvent event) {
        try {
            //the NetworkManager object
            NetworkManager networkManager = NetworkManager.getInstance();
            networkManager.start();
            networkManager.addErrorListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    NetworkEvent n = (NetworkEvent) evt;
                    n.getError().printStackTrace();
                }
            });
            ConnectionRequest cr = new ConnectionRequest() {
                @Override
                public void readResponse(InputStream input) throws IOException {
                    try {
                        Result result = Result.fromContent(input, Result.XML);
                        int Pocetak;
                        int Kraj;
                        String response;
                        response = result.toString();
                        
                    } catch (Exception ex) {
                        Dialog.show(ex.toString(), null, "OK", "Cancel");
                    }
                }
            };
            InfiniteProgress i = new InfiniteProgress();
            Dialog blocking = i.showInifiniteBlocking();
            cr.setDisposeOnCompletion(blocking);
            String grad = findComboBoxGrad().getSelectedItem().toString();
            String ulica = findComboBoxUlice().getSelectedItem().toString();
            String broj = findTxtBroj().getText();
            String tablica = findTxtTablica().getText();
            String drzava = findComboBoxDrzava1().getSelectedItem().toString();
            String marka = findComboBoxMarka().getSelectedItem().toString();
            String model = findTxtModel().getText();
            String slika1 = findLblSlika1().getText();
           
           
            String putanja;
            putanja = "http://xxx.xxx.xx.xx/wspauk/wspauk.asmx/prvovozilo";
            cr.setPost(false);
            cr.setReadResponseForErrors(true);
            //cr.setFollowRedirects(true);
           
           cr.setContentType("application/soap+xml; charset=utf-8");
           
            cr.addArgument("appid", "1");
            cr.addArgument("un", "yowo");
            cr.addArgument("pwd", "test");
            cr.addArgument("appid", "1");
            cr.addArgument("grad", grad);
            cr.addArgument("ulica", ulica);
            cr.addArgument("broj", broj);
            cr.addArgument("tablica", tablica);
            cr.addArgument("drzava", drzava);
            cr.addArgument("marka", marka);
            cr.addArgument("model", model);
            cr.addArgument("slika1", slika1);
            cr.addArgument("slika2", "slika1");
            cr.addArgument("slika3", "slika1");
            cr.addArgument("slika4", "slika1");
            cr.addArgument("razlog", razlog);
            cr.addArgument("komentar", komentar);
                                  
            cr.setUrl(putanja);
           
            NetworkManager.getInstance().addToQueue(cr);
        } catch (Exception e) {
            Dialog.show(e.toString(), null, "OK", "Cancel");
        }
    }

Shai Almog

unread,
Oct 17, 2013, 2:24:39 PM10/17/13
to codenameone...@googlegroups.com
We don't have a limit but both servers and devices often have a limit frequently its 1024 bytes.
Why not just use post which has bigger limits?

If you want to upload binary data post will fail too (since it still has server/protocol limits), for that we provide the multipart API which has no limits in terms of size (at least in theory).

Jovo Mirkovic

unread,
Oct 17, 2013, 5:08:51 PM10/17/13
to codenameone...@googlegroups.com
Thanks Shai.
 
I'll try change cr.setPost(false); to cr.setPost(true);, but it not enough :)
Do you have sample about multipart API...? I want send same text information and few pictures from phone to server, and save it in database...
 
  

Shai Almog

unread,
Oct 18, 2013, 2:28:10 AM10/18/13
to codenameone...@googlegroups.com
Make sure your server supports post, it won't work if your server just implements get.
Just replace ConnectionRequest with MultipartRequest (its a subclass so they are pretty compatible). You can then add a binary file instead of Base64 encoding and the multipart aspect will kick in.

Notice that on the server you will have to accept multipart which isn't trivial:
https://www.google.co.il/search?q=multipart+request&ie=utf-8&oe=utf-8&rls=org.mozilla:en-US:official&client=firefox-a&gws_rd=cr&ei=6dRgUuftGZL20gXj1YGQDg#q=multipart+request+servlet&rls=org.mozilla:en-US%3Aofficial
Reply all
Reply to author
Forward
0 new messages