0

My Code

I am trying to send custom headers to a host but when they received the data they are not receiving the headers:

request = (HttpWebRequest)WebRequest.Create(Common.GatewayUrl(Gateway, UsingTestGateway));
strCookieHeader = "[machine=" + ThreeDSecure.Cavv + " path=null domain=null; ]";
request.Headers.Add("cookies", strCookieHeader);
//request.Headers.Add("machine", ThreeDSecure.Cavv);
//request.Headers.Add("path", "null");
//request.Headers.Add("domain", "null");
//request.ContentType = Common.ContentType(Gateway);
//request.Headers[HttpRequestHeader.Cookie] = strCookieHeader;
//request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
request.Credentials = merchantCredentials;
request.ContentLength = requestData.Length;
request.Timeout = 60000;
request.Method = "POST";

sw = new StreamWriter(request.GetRequestStream());
sw.Write(requestData);
sw.Flush();
sw.Close();

response = (HttpWebResponse)request.GetResponse();
sr = new StreamReader(response.GetResponseStream());
responseData = sr.ReadToEnd();

sr.Close();
Ali
  • 3,373
  • 5
  • 42
  • 54
  • 2
    To manipulate the cookies header, you should use the WebRequest's `CookieContainer` property. – spender Feb 23 '17 at 16:49
  • [http://stackoverflow.com/questions/2972643/how-to-use-cookies-with-httpwebrequest](http://stackoverflow.com/a/2972725/14357) – spender Feb 23 '17 at 16:50
  • Or even better, don't use `WebRequest`, it's awful to use for many reasons. Better use `HttpClient` instead. – DavidG Feb 23 '17 at 16:55

0 Answers0