internal bool SendOutTo(Stream stream) { bool result = false; try { BinaryWriter binaryWriter = new BinaryWriter(stream); binaryWriter.Write($"{MethodType.ToString().ToUpper()} {CurrentUri.PathAndQuery} HTTP/1.1".GetASCIIBytes()); binaryWriter.Write(EOL); SendHeaders(binaryWriter); binaryWriter.Write(EOL); byte[] array = (RawData != null) ? RawData : (((object)FieldsImpl == null) ? null : FieldsImpl.get_data()); if (array != null && array.Length > 0) { binaryWriter.Write(array, 0, array.Length); } result = true; return result; } catch { return result; } }
private void SendHeaders(BinaryWriter stream) { SetHeader("Host", CurrentUri.Host); if (IsRedirected && !HasHeader("Referer")) { AddHeader("Referer", Uri.ToString()); } if (!HasHeader("Accept-Encoding")) { AddHeader("Accept-Encoding", "gzip, deflate, identity"); } if (!HasHeader("Connection")) { AddHeader("Connection", (!IsKeepAlive) ? "Close, TE" : "Keep-Alive, TE"); } if (!HasHeader("TE")) { AddHeader("TE", "chunked, identity"); } byte[] entityBody = GetEntityBody(); int num = (entityBody != null) ? entityBody.Length : 0; if (RawData == null) { byte[] array = ((object)FieldsImpl == null) ? null : FieldsImpl.get_data(); if (array != null && array.Length > 0 && !HasHeader("Content-Type")) { AddHeader("Content-Type", "application/x-www-form-urlencoded"); } } if (!HasHeader("Content-Length") && num != 0) { AddHeader("Content-Length", num.ToString()); } if (Credentials != null) { switch (Credentials.Type) { case AuthenticationTypes.Basic: SetHeader("Authorization", "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(Credentials.UserName + ":" + Credentials.Password))); break; case AuthenticationTypes.Unknown: case AuthenticationTypes.Digest: { Digest digest = DigestStore.Get(CurrentUri); if (digest != null) { string value = digest.GenerateResponseHeader(this); if (!string.IsNullOrEmpty(value)) { SetHeader("Authorization", value); } } break; } } } foreach (KeyValuePair<string, List<string>> header in Headers) { byte[] aSCIIBytes = (header.Key + ": ").GetASCIIBytes(); for (int i = 0; i < header.Value.Count; i++) { stream.Write(aSCIIBytes); stream.Write(header.Value[i].GetASCIIBytes()); stream.Write(EOL); } } }
internal byte[] GetEntityBody() { return (RawData != null) ? RawData : (((object)FieldsImpl == null) ? null : FieldsImpl.get_data()); }