gpt4 book ai didi

java - http post请求参数限制

转载 作者:行者123 更新时间:2023-12-02 09:49:03 25 4
gpt4 key购买 nike

我尝试将 19 个(图像)参数传递给 htttp post 请求,但是当我输入超过 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时才可以

最佳答案

您应该考虑使用Retrofit ,它允许以 block 的形式上传巨大的文件,并且比大多数库具有更大的灵 active 。

关于java - http post请求参数限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56452158/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com