Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 478419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:41:23+00:00 2026-05-13T00:41:23+00:00

I’m trying to create/modify dotclear blogs. For most of the options, I use XmlRpc

  • 0

I’m trying to create/modify dotclear blogs.

For most of the options, I use XmlRpc API (DotClear.MetaWeblog). But I didn’t find any way to handle categories.

So I start to look at the Http packet and try to do “the same as the browser”.

  1. Here is the method I use to “Http POST”

    protected HttpStatusCode HttpPost(Uri url_, string data_, bool allowAutoRedirect_)
    {
        HttpWebRequest Request;
        HttpWebResponse Response = null;
        Stream ResponseStream = null;
        Request = (System.Net.HttpWebRequest)HttpWebRequest.Create(url_);
        Request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5 (.NET CLR 3.5.30729)";
        Request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
        Request.AllowAutoRedirect = allowAutoRedirect_;
        // Add the network credentials to the request.
        Request.Credentials = new NetworkCredential(Username, Password);
    
        string authInfo = Username + ":" + Password;
        authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
        Request.Headers["Authorization"] = "Basic " + authInfo; 
    
        Request.Method = "POST";
        Request.CookieContainer = Cookies;
        if(ConnectionCookie!=null)
            Request.CookieContainer.Add(url_, ConnectionCookie);
        if (dcAdminCookie != null)
            Request.CookieContainer.Add(url_, dcAdminCookie);
        Request.PreAuthenticate = true;
    
        ASCIIEncoding encoding = new ASCIIEncoding();
        string postData = data_;
        byte[] data = encoding.GetBytes(postData); //Encoding.UTF8.GetBytes(data_);  //encoding.GetBytes(postData);
        Request.ContentLength = data.Length;
        Request.ContentType = "application/x-www-form-urlencoded";
        Stream newStream = Request.GetRequestStream();
        // Send the data.
        newStream.Write(data, 0, data.Length);
        newStream.Close();
    
        try
        {
            // get the response from the server.
            Response = (HttpWebResponse)Request.GetResponse();
            if (!allowAutoRedirect_)
            {
                foreach (Cookie c in Response.Cookies)
                {
                    if (c.Name == "dcxd")
                        ConnectionCookie = c;
                    if (c.Name == "dc_admin")
                        dcAdminCookie = c;
    
                }
    
                Cookies.Add(Response.Cookies);
            }
            // Get the response stream.
            ResponseStream = Response.GetResponseStream();
            // Pipes the stream to a higher level stream reader with the required encoding format. 
            StreamReader readStream = new StreamReader(ResponseStream, Encoding.UTF8);
            string result = readStream.ReadToEnd();
    
            if (Request.RequestUri == Response.ResponseUri)
            {
                _log.InfoFormat("{0} ==> {1}({2})", Request.RequestUri, Response.StatusCode, Response.StatusDescription);
            }
            else
            {
                _log.WarnFormat("RequestUri:{0}\r\nResponseUri:{1}\r\nstatus code:{2} Status descr:{3}", Request.RequestUri, Response.ResponseUri, Response.StatusCode, Response.StatusDescription);
            }
        }
        catch (WebException wex)
        {
            Response = wex.Response as HttpWebResponse;
    
            if (Response != null)
            {
                _log.ErrorFormat("{0} ==> {1}({2})", Request.RequestUri, Response.StatusCode, Response.StatusDescription);
            }
    
            Request.Abort();
        }
        finally
        {
            if (Response != null)
            { 
                // Releases the resources of the response.
                Response.Close();
            }
    
        }
        if(Response !=null)
            return Response.StatusCode;
    
        return HttpStatusCode.Ambiguous;
    }
    
  2. So the first thing to do is to Authenticate as admin. Here is the code:

    protected bool HttpAuthenticate()
    {
        Uri u = new Uri(this.Url);
        Uri url = new Uri(string.Format("{0}/admin/auth.php", u.GetLeftPart(UriPartial.Authority)));
        string data = string.Format("user_id={0}&user_pwd={1}&user_remember=1", Username, Password);
        var ret = HttpPost(url,data,false);
        return (ret == HttpStatusCode.OK || ret==HttpStatusCode.Found);
    }
    
  3. Now that I’m authenticated, I need to get a xd_chek info (that I can find on the page so basically it’s a GET on /admin/category.php + Regex(dotclear[.]nonce = '(.*)'))

  4. So I’m authenticated and have the xd_check info. The last thing to do seems to post the next category. But of course it does not work at all… Here is the code:

    string postData = string.Format("cat_title={0}&new_cat_parent={1}&xd_check={2}", category_, 0, xdCheck);
    HttpPost(url, postData, true);
    

Where am I going wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T00:41:23+00:00Added an answer on May 13, 2026 at 12:41 am

    Finaly I found the solution.

    It seems that the cookies where lost between anthentication and use of the pages.

    So I decide to not use de CookiesContainer of the framework but simply keep the cookies in a string and pass them at every request.

    And it works great !

    code exemple:

    private string _cookieAsString = string.Empty;
    
        protected string CookieAsString
        {
            get { return _cookieAsString; }
            set
            {
                if (value != null)
                {
                    if (!_cookieAsString.Contains(value))
                    {
                        if (_cookieAsString.Length == 0)
                            _cookieAsString = value;
                        else
                            _cookieAsString += string.Format(";{0}", value);
                    }
                }
            }
        }
    

    And in the HttpWebRequest, I set it this way:

    ...
    Request.Headers.Add(HttpRequestHeader.Cookie, CookieAsString);
    ...
    

    And keep the cookies in the httpWebRequest like this:

    ...
    CookieAsString = Response.Headers[HttpResponseHeader.SetCookie];
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm trying to create an if statement in PHP that prevents a single post
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.