Skip to content

Instantly share code, notes, and snippets.

@oscarkuo
Created November 21, 2016 03:49
Show Gist options
  • Save oscarkuo/63fe9ae8664ec0a38f34a653fbfa4509 to your computer and use it in GitHub Desktop.
Save oscarkuo/63fe9ae8664ec0a38f34a653fbfa4509 to your computer and use it in GitHub Desktop.
protected static WebRequest CreateRequest(string url, string secret)
{
var xml = @"
<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:ns=""https://service/1/0"">
<soapenv:Header/>
<soapenv:Body>
<ns:Request>
<ns:FirstName>XXX</ns:FirstName>
<ns:LastName>YYY</ns:LastName>
</ns:Request>
</soapenv:Body>
</soapenv:Envelope>";
var c = Encoding.UTF8.GetBytes(xml);
var wr = (HttpWebRequest)WebRequest.Create(url);
wr.ProtocolVersion = HttpVersion.Version11;
wr.ContentType = "text/xml;charset=utf-8";
wr.ContentLength = xml.Length;
wr.Accept = "text/xml";
wr.Headers.Add("SOAPAction", "\"\"");
wr.Headers.Add("Secret", secret);
wr.Method = "POST";
wr.GetRequestStream().Write(c, 0, c.Length);
return wr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment