Bir sunucuya bazı gönderi verilerini göndermeyi denemek için Apache HttpClient kullanıyorum. Ne yazık ki, herhangi bir günlük bilgisi almak için sunucuya erişimim yok, bu mümkün olmayacak.HttpClient'ten 500 hata alıyor, tarayıcıda çalışıyor
Bu işlem Firefox ile devam ederse, iyi çalışıyor. (Bu sayfada 302 uyarısı alıyorum)
Hem Firefox'un istek başlıklarını hem de programımı eşleştirdim.
Firefox Talebi Başlıkları:
Host: server ip
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:56.0) Gecko/20100101 Firefox/56.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Referer: https://server ip/
Content-Type: application/x-www-form-urlencoded
Content-Length: 407
Cookie: sessionId=blahblah
Connection: keep-alive
Upgrade-Insecure-Requests: 1
Benim Programlar İstek Başlıkları EntityUtils.toString(httpPost.getEntity(), "UTF-8");
çıktısını ve için aracı inşa Firefox'un karşılaştırarak context.getRequest().getAllHeaders();
Host: server ip
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:55.0) Gecko/20100101 Firefox/55.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Referer: https://server ip/
Content-Type: application/x-www-form-urlencoded
Connection: keep-alive
Upgrade-Insecure-Requests: 1
Content-Length: 406
Cookie: sessionId=blahblah
Ben istek gövdesini eşleştirdiniz gelen gösterilen araç, istek gövdesine bakacak ve karakter için neredeyse karakterle eşleşiyor. (Aynı oturum kullanılmadığı için beklenen oturum kimliğindeki küçük bir fark.)
Başka ne kontrol edeceğimi bilmiyorum. Sunucunun Tarayıcı ile program arasında farklı davranmasına neden olan nedir?
POST isteğim için kodum aşağıda.
HttpPost httpPost = new HttpPost("https://" + getIp() + "");
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("FTPUsername", "blah"));
params.add(new BasicNameValuePair("FTPPassword", "blah"));
params.add(new BasicNameValuePair("FormButtonSubmit", "OK"));
httpPost.setEntity(new UrlEncodedFormEntity(params));
httpPost.setHeader("Host", ip);
httpPost.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:55.0) Gecko/20100101 Firefox/55.0");
httpPost.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
httpPost.setHeader("Accept-Language", "en-US,en;q=0.5");
httpPost.setHeader("Accept-Encoding", "gzip, deflate, br");
httpPost.setHeader("Referer", referer);
httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
httpPost.setHeader("Connection", "keep-alive");
httpPost.setHeader("Upgrade-Insecure-Requests", "1");
//Response
HttpResponse response = getHttpClient().execute(httpPost, LoginRequest.context);
int statusCode = response.getStatusLine().getStatusCode();
httpPost.releaseConnection();
Ben 500 sunucu hatası olduğu için bu muhtemelen çok şey olabilir farkındayım ama yanlış teslim ediyorum ya tarayıcıda mükemmel çalışıyor gibi bir şey eksik bir şey olmalı.
@Justas Bir istekte bulunu? Bunun işe yarayacağını düşünmüyorum. – eis
@Austin sunucu tarafında bir oturum var gibi görünüyor, belki bu oturumda çalışmasına izin veren firefox ile önceki istekleri koymak bir şey var. Htmlunit, phantomjs veya benzeri gibi başsız bir tarayıcıyı deneyebilirsiniz. – eis
Bu fotoğraftan çıkmış olsa da, 'Content-Length: 406' nı neden firefox’un 'Content-Length: 407' başlıklarından daha az olduğunu bana bildirebilir miydiniz? isteğiniz cevapsız mı? – nullpointer