HttpWebRequest Credintial fejler
Hej Eksperterjeg forsøger at få adgang til WorlPays modul. Spørgmålet her er det samme som jeg laver:
http://forums.asp.net/p/1501279/3553954.aspx
Her findes andre programmeringssprog som laver det jeg skal kunne lave:
http://support.worldpay.com/support/gg/index.php?page=examples&%3bc=WW
I den anden ende får jeg Authentication Errors
[2016-08-17 09:19:20.267 (TID:a7c92d697cc3ec4b)] {INFO/XMLAuthFilter}: Authentication Failure : { ipAddress=XX.YY.z.14, userName="null", reason="No Auth Header" }
Mine Credintials fejler og jeg har forsøgt mig med mange muligherder.Blandt andet Credential 1 + 2 + 3, som I kan se her er udkommenteret:
public string XML2Bibitversion2(string sXML, string sURL, string sUser, string sPass)
{
HttpWebRequest request = null;
HttpWebResponse response = null;
byte[] bytes;
// sURL:
XDocument document = new XDocument();
try
{
// bytes = Encoding.ASCII.GetBytes("" +sXML +"," +sUser+","+sPass);
bytes = Encoding.ASCII.GetBytes(sXML);
request = (HttpWebRequest)WebRequest.Create(sURL);
request.PreAuthenticate = true;
// Credential 1
/*
CredentialCache mycache = new CredentialCache();
mycache.Add(new Uri(sURL), "Digest", new NetworkCredential(sUser, sPass));
request.Credentials = mycache;
*/
// Credential 2) Building my own Header
/*
string credentials = Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(sUser + ":" + sPass));
request.Headers.Add("Authorization", "Basic " + credentials);
*/
// Credential 3) Building my own Header
/*
string credentials = String.Format("{0}:{1}", sUser, sPass);
byte[] credbytes = Encoding.ASCII.GetBytes(credentials);
string base64 = Convert.ToBase64String(credbytes);
string authorization = String.Concat("Basic ", base64);
request.Headers.Add("Authorization", authorization);
*/
request.ContentType = "text/xml; encoding='utf-8'";
request.ContentLength = bytes.Length;
request.Method = "POST";
Stream requestStream = request.GetRequestStream();
requestStream.Write(bytes, 0, bytes.Length);
requestStream.Close();
Thread.Sleep(2000);
using (response = (HttpWebResponse)request.GetResponse())
{
if (response.StatusCode == HttpStatusCode.OK)
{
Stream responseStream = response.GetResponseStream();
string responseStr = new StreamReader(responseStream).ReadToEnd();
return responseStr;
}
return null;
}
}
catch (Exception ex)
{
return ex.ToString();
}
}