简体   繁体   中英

Http post request parameters limit

I'm try to pass 19(images) parameters to htttp post request, but when I put more then 9 params, my app don't do the upload to server, I recheck all the code and is ok, server side is ok also.

@Override
protected String doInBackground(Void... params) {
    Log.d("SETIMAGE", "IMAGEM DOINBACKGROUND INIT");
    RequestHandler rh = new RequestHandler();
    HashMap<String,String> param = new HashMap<String,String>();

    param.put(KEY_ID,id);
    param.put(KEY_CHAMADO,chamado);

    param.put(FACHADA,imageFachada);
    param.put(RADIO,imageRadio);
    param.put(SUPORTE,imageSuporte);
    param.put(MASTRO,imageMastro);
    param.put(ISOLAMENTO,imageIsolamento);
    param.put(INFRAEXT1,imageInfraExt1);
    param.put(INFRAEXT2,imageInfraExt2);
    param.put(INFRAINT1,imageInfraInt1);
    param.put(INFRAINT2,imageInfraInt2);
    param.put(CONECTOREXT,imageConectorExt);
    param.put(CONECTORINT,imageConectorInt);
    param.put(SALATEC,imageSalaTec);
    param.put(RACK,imageRack);
    param.put(IDU,imageIDU);
    param.put(TOMADAIDU,imageTomadaIDU);
    param.put(AZIMUTE,imageAzimute);
    param.put(GPS,imageGPS);
    param.put(MTCABOEXT,imageMtCaboExt);
    param.put(MTCABOINT,imageMtCaboInt);

    String result = rh.sendPostRequest(UploadUrl, param);
    Log.d("RESULT", result);
    return result;
}

This is via RequestHandler.class

public String sendPostRequest(String requestURL, HashMap<String, String> postDataParams) {
    //Creating a URL
    URL url;

    //StringBuilder object to store the message retrieved from the server
    StringBuilder sb = new StringBuilder();
    try {
        //Initializing Url
        url = new URL(requestURL);

        //Creating an httmlurl connection
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();

        //Configuring connection properties
        conn.setReadTimeout(150000);
        conn.setConnectTimeout(150000);
        conn.setRequestMethod("POST");
        conn.setDoInput(true);
        conn.setDoOutput(true);

        //Creating an output stream
        OutputStream os = conn.getOutputStream();

        //Writing parameters to the request
        //We are using a method getPostDataString which is defined below
        BufferedWriter writer = new BufferedWriter(
                new OutputStreamWriter(os, "UTF-8"));
        writer.write(getPostDataString(postDataParams));

        writer.flush();
        writer.close();
        os.close();
        int responseCode = conn.getResponseCode();

        if (responseCode == HttpsURLConnection.HTTP_OK) {
            BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            sb = new StringBuilder();
            String response;
            //Reading server response
            while ((response = br.readLine()) != null) {
                sb.append(response);
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
    return sb.toString();
}

I need to pass all images to upload to server. But it's ok only when I pass 9 param.put

您应该考虑使用Retrofit ,它允许分块上传大型文件,并且比大多数库具有更大的灵活性。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM