좋습니다. 이렇게하면 길어 지므로 끝까지 읽는 모든 사람에게 도움이됩니다.헤더, 쿠키, 매개 변수가있는 HttpPost - 417 - 기대가 실패했습니다.
전제 조건 : 서버에 액세스 할 수 없습니다. 단지 뉴스 덧글로 데이터를 게시하려고합니다.
필자는 필사적으로 몇 시간 동안 이것을 시험하고 있지만 아직 성공하지 못했습니다. 특별한
POST http://www.example.com/gen/processtalkback.php
Cookie: userid=XXXX; password=XXXX
Content-Type: application/x-www-form-urlencoded
reference_id=XXXX&talkback_command=newentry&talkback_content=comment&talkback_viewpage=1&reference_area=11
그래서 아무것도 두 쿠키 및 콘텐츠 discriptor와 5 개 개의 매개 변수와 두 헤더 : 내가 기본적으로 필요한 것은 요청의 종류이다. 두 쿠키는 필수입니다, 그래서 나는이처럼 설정 : 나는 HttpPost 객체에 헤더와 내용을 설정 그 후
CookieStore cookieStore = httpClient.getCookieStore();
BasicClientCookie cookie = new BasicClientCookie("userid", "XXXX");
cookie.setDomain("http://www.example.com");
cookieStore.addCookie(cookie);
BasicClientCookie cookie2 = new BasicClientCookie("password", "XXXX");
cookie2.setDomain("http://www.example.com");
cookieStore.addCookie(cookie2);
을하고 실행 : 나는 응답 들여다
HttpPost httpost = new HttpPost("http://www.example.com/gen/processtalkback.php");
httpost.setHeader("Content-Type", "application/x-www-form-urlencoded");
List<NameValuePair> nvps = new ArrayList<NameValuePair>(5);
nvps.add(new BasicNameValuePair("reference_id", "XXXX"));
...
httpost.setEntity(new UrlEncodedFormEntity(nvps));
HttpResponse httpResponse = httpClient.execute(httpost);
및 그것은 나를 보여줍니다 :
Log.i("RESPONSE", httpResponseActivity.getStatusLine() + EntityUtils.toString(httpResponse .getEntity()));
HTTP/1.1 417 Expectation Failed
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>417 - Expectation Failed</title>
</head>
<body>
<h1>417 - Expectation Failed</h1>
</body>
</html>
나는 정말로이 문제가 무엇인지 모른다. "포스터"또는 "HttpRequester"와 같은 파이어 폭스 확장 기능으로 내가 게시와 성공 :
HttpParams params = new BasicHttpParams();
params.setParameter("reference_id", "XXXX");
...
httpost.setParams(params);
의 원인이 될 수있는 무엇 :
POST http://www.example.com/gen/processtalkback.php
Cookie: userid=XXXX; password=XXXX
Content-Type: application/x-www-form-urlencoded
reference_id=XXXX&talkback_command=newentry&talkback_content=comment&talkback_viewpage=1&reference_area=11
200 OK
X-Powered-By: PHP/5.3.6
Set-Cookie: ...
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Date: Sun, 07 Aug 2011 16:24:01 GMT
Server: lighttpd/1.4.22
<a name="commentanchor"></a>
...
나는 또한 매개 변수 개체와 여전히 성공없이 그것을 시도 문제? 내가 놓친 게 있니? 아파치 HttpClient의 특징은 무엇입니까? 나는 서버가 저에게이 실패로 뭔가를 말하고 있다는 사실을 알고 있어요, 그래서 웹에서 검색이에 대한 솔루션 중 하나 시도하지 : 여전히 성공을
params.setBooleanParameter("http.protocol.expect-continue", false);
합니다.
Data:
POST /gen/processtalkback.php
HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Content-Length: 119
Host: www.example.com
Connection: Keep-Alive
User-Agent: Apache-HttpClient/UNAVAILABLE (java 1.4)
reference_id=XXXX...............
HEX: .....
내가 브라우저에 의해 게시에서 방화범에 의해 가지고 무엇 : 매개 변수와 함께 지금
Data:
POST /gen/processtalkback.php
HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Content-Length: 119
Host: www.example.com
Connection: Keep-Alive
User-Agent: Apache-HttpClient/UNAVAILABLE (java 1.4)
Expect: 100-Continue
HEX: .....
그리고 :이 매개 변수없이 응용 프로그램에 의해 도청에서 "루트 상어"를 가지고 무엇
:
Host www.example.de
User-Agent Mozilla/5.0
Accept text/javascript, text/html, application/xml, text/xml, */*
Accept-Language en-us,de-de;q=0.8,en;q=0.5,de;q=0.3
Accept-Encoding gzip, deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
DNT 1
Connection keep-alive
X-Requested-With XMLHttpRequest
X-Prototype-Version 1.7
Content-Type application/x-www-form-urlencoded; charset=UTF-8
Referer ...
Content-Length 134
Cookie ...
Pragma no-cache
Cache-Control no-cache
프로그래밍 방식 httppost 시도에서 쿠키가 표시되지 않는 이유는 무엇입니까? 누군가가 아이디어를 갖고 있다면 그것은 대단 할 것입니다. :-)