This is a simple entry to the https site using the C # console application, I used the same with webservice. When I ran this, it froze. The violinist is downloaded and on the Auth tab I see No proxy authentication header. No WWW-Authenticate header.
I used to use Stream instead of MemoryStream. I commented on some of the things that I used before, but did not work as a preauthenticate.
I can log in to get a subscriber via IE using the same user and password. Can someone please tell me what happened?
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Web;
namespace Examples.System.Net
{
public class WebRequestPostExample
{
public static void Main()
{
Uri requestUri = new Uri("https://services.yesmail.com/enterprise/subscribers");
CredentialCache cache = new CredentialCache();
NetworkCredential nc = new NetworkCredential("user/user1", "password");
cache.Add(requestUri, "Basic", nc);
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(requestUri);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "application/xml;charset=ISO-8859-1";
string EmailAddress = "test999@test1.com";
string FirstName = "first";
string LastName = "Last";
StringBuilder Efulfill = new StringBuilder();
Efulfill.Append("EmailAddress" + HttpUtility.UrlEncode(EmailAddress));
Efulfill.Append("FirstName" + HttpUtility.UrlEncode(FirstName));
Efulfill.Append("LastName" + HttpUtility.UrlEncode(LastName));
byte[] byteData = Encoding.UTF8.GetBytes(Efulfill.ToString());
request.ContentType = "application/xml;charset=ISO-8859-1";
request.ContentLength = byteData.Length;
using (MemoryStream Stream = new MemoryStream(byteData))
{
Stream.Write(byteData, 0, byteData.Length);
Stream.Close();
}
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
using (Stream resStream = response.GetResponseStream())
{
StreamReader reader = new StreamReader(resStream, Encoding.Default);
Console.WriteLine(reader.ReadToEnd());
}
}
}
}
}
source
share