Http发布请求参数限制

时间:2019-06-04 22:34:09

标签: java android httprequest

我尝试将19(images)参数传递给htttp发布请求,但是当我放置了9个以上的参数时,我的应用程序未将其上传到服务器,因此我重新检查了所有代码,服务器端可以还可以。

@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;
}

这是通过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();
}

我需要传递所有图像以上传到服务器。但这只有在我通过9 param.put的情况下才可以

1 个答案:

答案 0 :(得分:1)

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