我尝试使用以下代码中的new Thread(new Runnable() {
@Override
public void run() {
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(URL_PREFIX + "?" + URLEncodedUtils.format(nameValuePairs, "utf-8"));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}).start();
向我的服务器发送数据。
Request-URI Too Long
The requested URL's length exceeds the capacity limit for this server.
Additionally, a 414 Request-URI Too Long error was encountered while trying to use an ErrorDocument to handle the request.
when check my httppost uri link length was 3497 char.
但是当我尝试将此数据发布到服务器时,我收到404错误代码,请求失败,当我尝试使用浏览器检查链接时,我得到以下内容。
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Pinger {
private static String keyWordTolookFor = "average";
public Pinger() {
// TODO Auto-generated constructor stub
}
public static void main(String[] args) {
//Test the ping method on Windows.
System.out.println(ping("192.168.0.1")); }
public String ping(String IP) {
try {
String line;
Process p = Runtime.getRuntime().exec("ping -n 1 " + IP);
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
while (((line = input.readLine()) != null)) {
if (line.toLowerCase().indexOf(keyWordTolookFor.toLowerCase()) != -1) {
String delims = "[ ]+";
String[] tokens = line.split(delims);
return tokens[tokens.length - 1];
}
}
input.close();
} catch (Exception err) {
err.printStackTrace();
}
return "Offline";
}
在我的代码中,我尝试发送base64编码的图像和一些其他参数。任何人都可以帮我解决这个问题吗?或任何其他方式来实现它?
答案 0 :(得分:1)
你不应该把params放到POST请求的url中,把它放在体内。
HttpPost httpPost = new HttpPost(URL_PREFIX);
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));
GET请求参数转到网址 POST请求参数通常会转到正文。