gpt4 book ai didi

android - 无法将大字符串上传到服务器

转载 作者:行者123 更新时间:2023-11-30 02:49:15 27 4
gpt4 key购买 nike

我正在尝试通过邮寄将字符串上传到服务器..这是我的代码..

String URL = "http://myUrl/add?user_id="+user_id
+ "&text=" + text
+ "&type=" + type;

URL = URL.replaceAll(" ", "%20");
URL = URL.replaceAll("\n", "%0A");
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(URL);

HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
String result = EntityUtils.toString(httpEntity);

} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

当我上传一个小字符串时,此代码有效。但是当我尝试发送大字符串(超过 2 行)时,例如,它不起作用。有什么建议吗?

谢谢你:)

最佳答案

Method Get has Maximium Chars limit , 而不是使用发布

String URL = "http://myUrl/add";
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(URL);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("user_id", user_id));
nameValuePairs.add(new BasicNameValuePair("text", text));
nameValuePairs.add(new BasicNameValuePair("type", type));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
String result = EntityUtils.toString(httpEntity);

} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

关于android - 无法将大字符串上传到服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24488395/

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