0

I began to learn ASP.NET and C#, to get more familiar with techniques I want to make plugin for open source BugTracker.Net application. Where I am stacked is that for adding new issue application need to get HttpWebRequest on insert_bug.aspx

I did make basic thing working on code like this:

string Url = "http://localhost:8090/insert_bug.aspx";
        string post_data =
                     "&username=admin"
                    + "&password=admin"
                    + "&short_desc=Description"
                    + "&comment=Comment"
                    + "&projectid=1"

        byte[] bytes = Encoding.UTF8.GetBytes(post_data);
        HttpWebResponse res = null;
        try
        {
            HttpWebRequest req = (HttpWebRequest) System.Net.WebRequest.Create(Url);
            req.Credentials = CredentialCache.DefaultCredentials;
            req.PreAuthenticate = 
            req.Method = "POST";
            req.ContentType= "application/x-www-form-urlencoded";
            req.ContentLength=bytes.Length;
            Stream request_stream = req.GetRequestStream();
            request_stream.Write(bytes,0,bytes.Length);
            request_stream.Close();
            res = (HttpWebResponse) req.GetResponse();
        }
        catch (Exception e)
        {
            Console.WriteLine("HttpWebRequest error url=" + Url);
            Console.WriteLine(e);
        }

I want to insert also CATEGORY into my issues and reading code on insert_bug.aspx i fund part for defining category for opening issue

if (Request["$CATEGORY$"] != null && Request["$CATEGORY$"] != "") { categoryid = Convert.ToInt32(Request["$CATEGORY$"]); }

Question: What and How I can add "$CATEGORY$" to my request so the issues I added have defined category.

1 Answer 1

1

If I understand your question correctly, if you want to add a category, you need to look up the category ID and add it as a variable in your POST data. For example, if the category you want has its ID=1 ("bug" in BugTracker.NET), then you'd use this:

    string post_data =
                 "&username=admin"
                + "&password=admin"
                + "&short_desc=Description"
                + "&comment=Comment"
                + "&projectid=1"
                + "&$CATEGORY$=1";

BTW, in simple HTTP client scenarios like this one you're better off using the WebClient class. You can accomplish the same thing in many fewer lines of code.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.