I'm using Apache HttpClient 4.0 for my web crawler. The behavior i found strange is: i'm trying to get page via HTTP GET method and getting response about 404 HTTP error. But if i try to get that page using browser it's done successfully.
Details: 1. I upload multipart form to server this way:
HttpPost httpPost = new HttpPost("http://[host here]/in.php");
MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
entity.addPart("method", new StringBody("post"));
entity.addPart("key", new StringBody("223fwe0923fjf23"));
FileBody fileBody 开发者_如何学Python= new FileBody(new File("photo.jpg"), "image/jpeg");
entity.addPart("file", fileBody);
httpPost.setEntity(entity);
HttpResponse response = httpClient.execute(httpPost);
HttpEntity result = response.getEntity();
String responseString = "";
if (result != null) {
InputStream inputStream = result.getContent();
byte[] buffer = new byte[1024];
while(inputStream.read(buffer) > 0)
responseString += new String(buffer);
result.consumeContent();
}
Uppload succefully ends.
I'm getting some results from web server:
HttpGet httpGet = new HttpGet("http://[host here]/res.php?key="+myKey+"&action=get&id="+id); HttpResponse response = httpClient.execute(httpGet); HttpEntity entity = response.getEntity();
I'm getting ClientProtocolException while execute method run. I was debugging this situation with log4j. Server answers "404 Not Found". But my browser loads me that page with no problem.
Can anybody help me?
Thank you.
I have to note the problem isn't concerned with web server. If i don't add FileBody to multipart form data, exception doesn't occure, all goes fine with no HTTP 404.
精彩评论