업데이트 : https URI로 데이터를 POST하려고합니다. POST는 HTTP 작동하지만 HTTPS URI 내가 웹 사이트에 데이터를 게시 할 EXE C#을을 윈폼 만드는 오전 안녕HTTPS POST in C#, Winforms (스트림 작성기, HttpWebResponse, HttpWebRequest)
실패합니다. 코드는 다음과 같습니다. 문제는 스트림이 내 게시물의 데이터를 복제한다 ..
예 :이 게시한다고 가정 - 나는 실제로 전송되는 어떤 트래픽을 검사 할 때 다음>username=bob
을 username=bobusername=bob
참조 ? 그것은 중복되며, 버퍼의 끝까지 한 번 더 같은 줄을 추가하고 보냅니다.
나는 이틀 동안 문제를 찾으려고 노력 중입니다. 어떤 신체가 이것을 해결할 수 있습니까? 아니면 몇 가지 힌트를주세요. .. 감사합니다
(콘텐츠 길이가 정확하게 12로 설정하지만 버퍼의 꼬리에 다시 한 번 같은 데이터를 추가 한 후, 24 바이트를 전송한다)
는 헤더가 있습니다
POST /login/ HTTP/1.0
Content-Type: application/x-www-form-urlencoded
Host: abc.test.com
Content-Length: 12
username=bobusername=bob
-
이것은 내가 현재 내가 라인 byte[] postBytes = Encoding.ASCII.GetBytes(post_data);
에 중단 점을 넣어 postBytes
올바른 데이터를 포함
string post_data = "username=bob";
string uri = "https://abc.test.com/login/";
HttpWebRequest request = (HttpWebRequest)
WebRequest.Create(uri);
request.KeepAlive = false;
request.ProtocolVersion = HttpVersion.Version10;
request.Method = "POST";
byte[] postBytes = Encoding.ASCII.GetBytes(post_data);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postBytes.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(postBytes, 0, postBytes.Length);
MessageBox.Show(postBytes.Length.ToString());
requestStream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream());
string tmp = sr.ReadToEnd().Trim();
사용하고있는 코드입니다 ...하지만 출력을 두 번 얻습니다.
왜 이런 일이 발생합니까? 나는 분명히 희망한다.
안녕하세요 jiaji 우, 시간과 도움을 주셔서 감사합니다. 나는 닫는 webresponse 시도했다. 그러나 그것의 사본을 여전히 보내고있다. 예, 뭔가 다른 것 같아요 .. –