0
votes
 private void Form1_Load(object sender, EventArgs e)
   {
       string site = "https://signin.ebay.com/ws/eBayISAPI.dll?co_partnerId=2&siteid=0&UsingSSL=1&MfcISAPICommand=SignInWelcome&userid=USERNAME&pass=PWD&sngBt=Sign%20in";
       CookieContainer cookieJar = new CookieContainer();

       HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(site);
       request.CookieContainer = cookieJar;

       HttpWebResponse response = (HttpWebResponse)request.GetResponse();
       System.IO.StreamReader sr = new System.IO.StreamReader(response.GetResponseStream());

       richTextBox1.Text = sr.ReadToEnd();
       foreach (Cookie c1 in response.Cookies)
       {
           richTextBox1.AppendText(c1.Name.ToString() + "\n\n");
       }
   }

I've been messing around with Fiddler and the headers for 2 days with nothing better. Please help me retrieve this last cookie. In the browser the URL will log you right in (Change USERNAME and PWD respectively), and returns ds2, ebay, dp1, cssg, nonsession cookies.. the code is missing the ebay cookie.

Request Headers:

Client

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8

Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

Accept-Encoding: gzip,deflate,sdch

Accept-Language: en-US,en;q=0.8

User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko)

Chrome/24.0.1312.56 Safari/537.17

Transport

Connection: keep-alive

Host: signin.ebay.com

 private void Form1_Load(object sender, EventArgs e)
   {
       string site = "https://signin.ebay.com/ws/eBayISAPI.dll?co_partnerId=2&siteid=0&UsingSSL=1&MfcISAPICommand=SignInWelcome&userid=USERNAME&pass=PWD&sngBt=Sign%20in";
       CookieContainer cookieJar = new CookieContainer();

        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(site);
        request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
        request.Headers.Add("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3");
        request.Headers.Add("Accept-Encoding: gzip,deflate,sdch");
        request.Headers.Add("Accept-Language: en-US,en;q=0.8");
        request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.56 Safari/537.17";

        request.CookieContainer = cookieJar;

       HttpWebResponse response = (HttpWebResponse)request.GetResponse();
       System.IO.StreamReader sr = new System.IO.StreamReader(response.GetResponseStream());

       richTextBox1.Text = sr.ReadToEnd();
       foreach (Cookie c1 in response.Cookies)
       {
           richTextBox1.AppendText(c1.Name.ToString() + "\n\n");
       }
   }

Fiddler will take me no further? this returns no source, but does return the ebay cookie..

2
I've seen similar issues. Try setting the user agent on the web request to a common browser's agent. I've had this work on other sites. stackoverflow.com/questions/642860/…Eli Gassert
nope, not the user-agent: tried those two + the fiddler result: User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.56 Safari/537.17user209214
eBay login is little more complicated!Parimal Raj
Your web browser settings are blocking cookies. <-- is sent as response!Parimal Raj
which cookie you are missing?Parimal Raj

2 Answers

1
votes

Well finally,

class Program
{

    static void Main(string[] args)
    {
        CookieContainer cookieJar = new CookieContainer();
        HTTP http = new HTTP(cookieJar);
        string user = "this is not my username";
        string pass = "this is not my password";

        //some cookies are set before login & they are needed for an user to login, for that reason only you were getting the error
        string responseData = http.DownloadString("https://signin.ebay.com/ws/eBayISAPI.dll?SignIn");

        string midParamValue = ParseMid(responseData, "name=\"mid\" id=\"mid\" value=\"", "\"");
        string bUrlPrfx = ParseMid(responseData, "id=\"bUrlPrfx\" value=\"", "\"");
        string rqid = ParseMid(responseData, "id=\"bUrlPrfx\" value=\"", "\"");
        string pdata =
            string.Format(
                "MfcISAPICommand=SignInWelcome&bhid=a1%253Dna%7Ea2%253Dna%7Ea3%253Dna%7Ea4%253DMozilla%7Ea5%253DNetscape%7Ea6%253D5.0%2520%28Windows%29%7Ea7%253D20100101%7Ea8%253Dna%7Ea9%253Dtrue%7Ea10%253DWindows%2520NT%25206.1%253B%2520WOW64%7Ea11%253Dtrue%7Ea12%253DWin32%7Ea13%253Dna%7Ea14%253DMozilla%252F5.0%2520%28Windows%2520NT%25206.1%253B%2520WOW64%253B%2520rv%253A18.0%29%2520Gecko%252F20100101%2520Firefox%252F18.0%7Ea15%253Dfalse%7Ea16%253Den-US%7Ea17%253Dna%7Ea18%253Dsignin.ebay.com%7Ea19%253Dna%7Ea20%253Dna%7Ea21%253Dna%7Ea22%253Dna%7Ea23%253D1366%7Ea24%253D768%7Ea25%253D24%7Ea26%253D738%7Ea27%253Dna%7Ea28%253DFri%2520Jan%252025%25202013%252022%253A20%253A09%2520GMT%252B0530%2520%28India%2520Standard%2520Time%29%7Ea29%253D5.5%7Ea30%253Dpdf%257Cpdf%257Cpdf%257C%7Ea31%253Dyes%7Ea32%253Dna%7Ea33%253Dna%7Ea34%253Dno%7Ea35%253Dno%7Ea36%253Dyes%7Ea37%253Dno%7Ea38%253Donline%7Ea39%253Dno%7Ea40%253DWindows%2520NT%25206.1%253B%2520WOW64%7Ea41%253Dno%7Ea42%253Dno%7Ea43%253D&UsingSSL=1&inputversion=2&lse=true&lsv=11.5.502&mid=AQAAAThpCRHvAAUxMzg5OTM0YzA2MS5hNWFiODMyLjJmNDcyLmZmZTlhOWUwEZMPFiRFo7yUjykHfCAFgp%2Bk9%2Bk*&kgver=1&kgupg=1&kgstate=r&omid=&hmid=&rhr=f&siteid=0&co_partnerId=2&ru=&pp=&pa1=&pa2=&pa3=&i1=-1&pageType=-1&rtmData=&bUrlPrfx={0}&rqid={1}&kgct=&userid={2}&pass={3}&keepMeSignInOption=1&sgnBt=Sign+in&htmid={4}&kdata=%251E%251F%2510%251E1359132609409%251E1%251F%2510%251E1359132609409%251E0%251F%2510%251E1359132609410%251E1%251F%2510%251E1359132609410%251E0%251F%251B%251E1359132612808%251E1%251F%2510%251E1359132612837%251E1%251F%2510%251E1359132612838%251E0%251F%251B%251E1359132612977%251E0%251F", bUrlPrfx, rqid, user,pass, midParamValue);
        responseData =
            http.UploadString("https://signin.ebay.com/ws/eBayISAPI.dll?co_partnerId=2&siteid=0&UsingSSL=1", pdata);


        PrintAllCookies(cookieJar);
        Console.Read();

    }

    private static void PrintAllCookies(CookieContainer cookies)
    {
        Hashtable table = (Hashtable)cookies.GetType().InvokeMember("m_domainTable",
                                                                     BindingFlags.NonPublic |
                                                                     BindingFlags.GetField |
                                                                     BindingFlags.Instance,
                                                                     null,
                                                                     cookies,
                                                                     new object[] { });



        foreach (string key in table.Keys)
        {
            foreach (Cookie cookie in cookies.GetCookies(new Uri(string.Format("http://{0}/", key.StartsWith(".", StringComparison.Ordinal) ? "www" + key : key))))
            {
                Console.WriteLine("Name = {0} ; Value = {1} ; Domain = {2}", cookie.Name, cookie.Value,
                                  cookie.Domain);
            }
        }
    }

    public static string ParseMid(string text, string firstString, string lastString)
    {

        string str = text;
        int pos1 = str.IndexOf(firstString, StringComparison.Ordinal) + firstString.Length;
        int pos2 = str.IndexOf(lastString, pos1 + 1, StringComparison.Ordinal);
        string finalString = str.Substring(pos1, pos2 - pos1);
        return finalString;
    } 
}

You will need a class that i used, its a simple WebClient that supports CookieContainer

The output :

The output of all cookies

Have printed cookie value to "none" as i logged in with my username :P


HTTP.cs

public class HTTP : WebClient
{
    public HTTP()
        : this(new CookieContainer())
    { }

    public HTTP(CookieContainer c)
    {
        CookieContainer = c;
    }
    public CookieContainer CookieContainer { get; set; }

    protected override WebRequest GetWebRequest(Uri address)
    {
        WebRequest request = base.GetWebRequest(address);

        var castRequest = request as HttpWebRequest;
        if (castRequest != null)
        {
            castRequest.CookieContainer = CookieContainer;
            castRequest.ServicePoint.Expect100Continue = false;
            castRequest.ContentType = "application/x-www-form-urlencoded";
        }

        return request;
    }

}
0
votes

namespace watcher { public partial class Form1 : Form { public Form1() { InitializeComponent(); }

    private void Form1_Load(object sender, EventArgs e)
    {
        CookieContainer cookieJar = new CookieContainer();
        HTTP http = new HTTP(cookieJar);
        string user = "id";
        string pass = "password";

        //some cookies are set before login & they are needed for an user to login, for that reason only you were getting the error
        string responseData = http.DownloadString("https://signin.ebay.com/ws/eBayISAPI.dll?SignIn");

        string midParamValue = ParseMid(responseData, "name=\"mid\" id=\"mid\" value=\"", "\"");
        string bUrlPrfx = ParseMid(responseData, "id=\"bUrlPrfx\" value=\"", "\"");
        string rqid = ParseMid(responseData, "id=\"bUrlPrfx\" value=\"", "\"");
        string hidUrl = ParseMid(responseData, "name=\"hidUrl\" value=\"", "\""); //"name=\"hidUrl\" value="http://my.ebay.com/ws/eBayISAPI.dll?MyeBay"
        //string lucky9 = ParseMid(responseData, 
        string pdata =
            string.Format(
                "MfcISAPICommand=SignInWelcome&bhid=a1%253Dna%7Ea2%253Dna%7Ea3%253Dna%7Ea4%253DMozilla%7Ea5%253DNetscape%7Ea6%253D5.0%2520%28Windows%29%7Ea7%253D20100101%7Ea8%253Dna%7Ea9%253Dtrue%7Ea10%253DWindows%2520NT%25206.1%253B%2520WOW64%7Ea11%253Dtrue%7Ea12%253DWin32%7Ea13%253Dna%7Ea14%253DMozilla%252F5.0%2520%28Windows%2520NT%25206.1%253B%2520WOW64%253B%2520rv%253A18.0%29%2520Gecko%252F20100101%2520Firefox%252F18.0%7Ea15%253Dfalse%7Ea16%253Den-US%7Ea17%253Dna%7Ea18%253Dsignin.ebay.com%7Ea19%253Dna%7Ea20%253Dna%7Ea21%253Dna%7Ea22%253Dna%7Ea23%253D1366%7Ea24%253D768%7Ea25%253D24%7Ea26%253D738%7Ea27%253Dna%7Ea28%253DFri%2520Jan%252025%25202013%252022%253A20%253A09%2520GMT%252B0530%2520%28India%2520Standard%2520Time%29%7Ea29%253D5.5%7Ea30%253Dpdf%257Cpdf%257Cpdf%257C%7Ea31%253Dyes%7Ea32%253Dna%7Ea33%253Dna%7Ea34%253Dno%7Ea35%253Dno%7Ea36%253Dyes%7Ea37%253Dno%7Ea38%253Donline%7Ea39%253Dno%7Ea40%253DWindows%2520NT%25206.1%253B%2520WOW64%7Ea41%253Dno%7Ea42%253Dno%7Ea43%253D&UsingSSL=1&inputversion=2&lse=true&lsv=11.5.502&mid=AQAAAThpCRHvAAUxMzg5OTM0YzA2MS5hNWFiODMyLjJmNDcyLmZmZTlhOWUwEZMPFiRFo7yUjykHfCAFgp%2Bk9%2Bk*&kgver=1&kgupg=1&kgstate=r&omid=&hmid=&rhr=f&siteid=0&co_partnerId=2&ru=&pp=&pa1=&pa2=&pa3=&i1=-1&pageType=-1&rtmData=&bUrlPrfx={0}&rqid={1}&kgct=&userid={2}&pass={3}&keepMeSignInOption=1&sgnBt=Sign+in&htmid={4}&kdata=%251E%251F%2510%251E1359132609409%251E1%251F%2510%251E1359132609409%251E0%251F%2510%251E1359132609410%251E1%251F%2510%251E1359132609410%251E0%251F%251B%251E1359132612808%251E1%251F%2510%251E1359132612837%251E1%251F%2510%251E1359132612838%251E0%251F%251B%251E1359132612977%251E0%251F", bUrlPrfx, rqid, user, pass, midParamValue);
        responseData =
            http.UploadString("https://signin.ebay.com/ws/eBayISAPI.dll?co_partnerId=2&siteid=0&UsingSSL=1", pdata);
        richTextBox1.Text = responseData;

        PrintAllCookies(cookieJar);
    }
    private void PrintAllCookies(CookieContainer cookies)
    {
        Hashtable table = (Hashtable)cookies.GetType().InvokeMember("m_domainTable",
                                                                     BindingFlags.NonPublic |
                                                                     BindingFlags.GetField |
                                                                     BindingFlags.Instance,
                                                                     null,
                                                                     cookies,
                                                                     new object[] { });

        foreach (string key in table.Keys)
        {
            foreach (Cookie cookie in cookies.GetCookies(new Uri(string.Format("http://{0}/", key.StartsWith(".", StringComparison.Ordinal) ? "www" + key : key))))
            {
                richTextBox1.AppendText("Name = " + cookie.Name.ToString() + " Value = " + cookie.Value.ToString() + "Domain = " + cookie.Domain.ToString() + "\n\n");
            }
        }
    }

    public string ParseMid(string text, string firstString, string lastString)
    {

        string str = text;
        int pos1 = str.IndexOf(firstString, StringComparison.Ordinal) + firstString.Length;
        int pos2 = str.IndexOf(lastString, pos1 + 1, StringComparison.Ordinal);
        string finalString = str.Substring(pos1, pos2 - pos1);
        return finalString;
    }
    public class HTTP : WebClient
    {
        public HTTP()
            : this(new CookieContainer())
        { }

        public HTTP(CookieContainer c)
        {
            CookieContainer = c;
        }
        public CookieContainer CookieContainer { get; set; }

        protected override WebRequest GetWebRequest(Uri address)
        {
            WebRequest request = base.GetWebRequest(address);

            var castRequest = request as HttpWebRequest;
            if (castRequest != null)
            {
                castRequest.CookieContainer = CookieContainer;
                castRequest.ServicePoint.Expect100Continue = false;
                castRequest.ContentType = "application/x-www-form-urlencoded";
                //castRequest.AllowAutoRedirect = true;
                castRequest.Headers.Add("Cache-Control", "max-age=0");
                castRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
                castRequest.Headers.Add("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.3");
                //castRequest.Headers.Add("Accept-Encoding", "gzip,deflate,sdch");
                castRequest.Headers.Add("Accept-Language", "en-US,en;q=0.8");
                castRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.57 Safari/537.17";

                castRequest.Headers.Add("Origin", "https://signin.ebay.com");
                castRequest.Referer = "https://signin.ebay.com/ws/eBayISAPI.dll?SignIn";
                castRequest.KeepAlive = true;
                castRequest.Host = "signin.ebay.com";
            }

            return request;
        }
    }
}
}

i added some more headers, the packet looks similar to a normal login packet, but still erroring at either lucky9 or a url redirect? I'm not sure about troubleshooting this further.. i've attempted to modify the url with the &ru=http%3A%2F%2Fmy.ebay.com%2Fws%2FeBayISAPI.dll%3FMyEbayBeta%26MyeBay%3D%26guest%3D1&pageType=3984 header, but it accomplished nothing. Someone else will have to help with the final step.

<script type="text/javascript" src="https://secureir.ebaystatic.com/v4js/z/i5/r32gctn0fu3vjkpge2mjhij3q.js#SYS-ZAM_vjo_e809_1_Ear_en_US"></script>
<script type="text/javascript">vjo.dsf.error.ErrorHandlerManager.register(new vjo.dsf.error.DefaultErrorHandler());
vjo.dsf.error.ErrorHandlerManager.enableOnError(true, false);
vjo.dsf.cookie.VjCookieJar.sCookieDomain = '.ebay.com';vjo.dsf.cookie.VjCookieJar.writeCookielet('ebay','js','1');
</script>
<script language="JavaScript">window.location="http://my.ebay.com/ws/eBayISAPI.dll?MyEbayBeta&MyeBay=&guest=1"</script>
<div class="pagewidth">
    <div class="pageminwidth">
        <div class="pagelayout">
            <div class="pagecontainer">
                <div class="GlobalNavigation" id="GlobalNavigation"><div><script type="text/javascript">var _GlobalNavHeaderUtf8Encoding=true,includeHost='https://secureinclude.ebaystatic.com/';</script>

                <div class="CentralArea" id="CentralArea"><div>      <form name="AlertSuppressor" method="post"><input type="hidden" name="hidUrl" value="http://my.ebay.com/ws/eBayISAPI.dll?MyEbayBeta&amp;MyeBay=&amp;guest=1"></form>      <noscript><meta http-equiv="Refresh" content="0; url = http://my.ebay.com/ws/eBayISAPI.dll?MyEbayBeta&amp;MyeBay=&amp;guest=1"></noscript>
<b>If you are seeing this page, your browser settings prevent you from automatically redirecting to a new URL.</b></td></tr></table>
<div class="buttonDiv_space"><a href="http://my.ebay.com/ws/eBayISAPI.dll?MyEbayBeta&amp;MyeBay=&amp;guest=1">Continue</a>
<div class="SupportiveNavigation" id="SupportiveNavigation">
<script type="text/javascript">vjo.dsf.cookie.VjCookieJar.writeCookieEx("lucky9", "8067469", 730);
</script>

Name = ebay Value = ###

Name = dp1 Value = ###

Name = cssg Value = ###

Name = s Value = ###

Name = nonsession Value = ###

Name = cid Value = ###

Name = ds1 Value = ###

Name = ns1 Value = ###

Name = secses Value = ###

Name = shs Value = ###