Click here to Skip to main content
15,889,863 members
Home / Discussions / C#
   

C#

 
AnswerRe: Treeview node folder images Pin
SaqibRasheed23-Aug-13 2:19
SaqibRasheed23-Aug-13 2:19 
QuestionChart ToolTip using #VALX as Key of a dictionary Pin
PozzaVecia20-Aug-13 11:43
PozzaVecia20-Aug-13 11:43 
QuestionASP.NET - Dynamic Control ? Or Some other idea ? Pin
Forbiddenx20-Aug-13 9:42
Forbiddenx20-Aug-13 9:42 
SuggestionRe: ASP.NET - Dynamic Control ? Or Some other idea ? Pin
Richard MacCutchan20-Aug-13 20:12
mveRichard MacCutchan20-Aug-13 20:12 
QuestionRetrieve all rows in MySQL stored procedure and put in in C# class. Pin
dudz artiaga20-Aug-13 3:24
dudz artiaga20-Aug-13 3:24 
AnswerRe: Retrieve all rows in MySQL stored procedure and put in in C# class. Pin
Simon_Whale20-Aug-13 4:55
Simon_Whale20-Aug-13 4:55 
AnswerRe: Retrieve all rows in MySQL stored procedure and put in in C# class. Pin
SaqibRasheed20-Aug-13 12:24
SaqibRasheed20-Aug-13 12:24 
QuestionGetting 403 (Forbidden) from HttpWebRequest Pin
Member 993503820-Aug-13 1:32
Member 993503820-Aug-13 1:32 
HI!

I tried to code a simple tool, that uploads my XML Files to www.meinpaket.de. But each time I try it, I get a 403 Exception.

Can someone explain me, what is wrong here? WebResponse oWebResponse = oWebRequest.GetResponse() is raising the Exception.

Thanks for Help

C#
public class MeinPaketRequest
    {
        public string TestURL { get; set; }
        public string URL { get; set; }
        public string Username { get; set; }
        public string Password { get; set; }
        public bool Test { get; set; }
        CookieContainer _cookies = new CookieContainer();


        public MeinPaketRequest()
        {
            this.TestURL = "https://mp-api.mepa-home.de/dealerapi/xml";
            this.URL = "https://www.meinpaket.de/dealerapi/xml";
            this.Test = true;
            this.Username = "Username";
            this.Password = "Password";
        }

        public string Request(string Filename)
        {
            if (string.IsNullOrWhiteSpace(Filename))
            {
                Filename = "C:\\Users\\TWGT-KASSE-2\\Desktop\\MeinPaket\\Beispieldateien_042013\\mp_example_30_01_download_orders.xml";
            }

            XmlDocument xDocument = new XmlDocument();
            xDocument.Load(Filename);

            foreach (XmlNode oNode in xDocument.ChildNodes)
            {
                if (oNode.Name == "dataRequest")
                {
                    foreach (XmlNode oNodeRequest in oNode.ChildNodes)
                    {
                        if (oNodeRequest.Name == "header")
                        {
                            foreach (XmlNode oNodeHeader in oNodeRequest.ChildNodes)
                            {

                                if (oNodeHeader.Name == "password")
                                    oNodeHeader.InnerText = this.Password;
                                
                                if (oNodeHeader.Name == "login")
                                    oNodeHeader.InnerText = this.Username;

                            }
                        }
                    }
                }
            }


            // Leerer WebRequest
            HttpWebRequest oWebRequest = null;

            if (this.Test)
            {
                // im Testbetrieb die Test URL nutzen
                oWebRequest = (HttpWebRequest)WebRequest.Create(this.TestURL);
            }
            else
            {
                // im LiveBetrieb die Live-URL nutzen
                oWebRequest = (HttpWebRequest)WebRequest.Create(this.URL);
            }

            // Test settings
            oWebRequest.CookieContainer = _cookies;
            oWebRequest.Accept = "*/*";
            oWebRequest.KeepAlive = true;
            oWebRequest.UseDefaultCredentials = true;
            oWebRequest.UserAgent = "Mozilla/5.0";
            oWebRequest.PreAuthenticate = true;
            

            // Credentials mit Username / Passwort erstellen
            oWebRequest.Credentials = new NetworkCredential(this.Username, this.Password);

            // ContentType ist Text/XML
            oWebRequest.ContentType = "text/xml";

            // Method ist POST
            oWebRequest.Method = "POST";

            // Encoding für den Inhalt ist UTF-8
            byte[] bytes = Encoding.UTF8.GetBytes(xDocument.InnerXml.ToString());

            // Länge des Request messen
            oWebRequest.ContentLength = bytes.Length;

            // Stream an MeinPaket übertragen
            using (Stream oStream = oWebRequest.GetRequestStream())
            {
                oStream.Write(bytes, 0, bytes.Length);
            }

            // Antwort von MeinPaket abholen
            using (WebResponse oWebResponse = oWebRequest.GetResponse())
            {
                // ohne Antwort kann nix zurückgegeben werden
                if (oWebResponse == null)
                    return null;

                // Antwort lesen
                using (StreamReader oStreamReader = new StreamReader(oWebResponse.GetResponseStream()))
                {
                    // Antwort zurückgeben
                    return oStreamReader.ReadToEnd().Trim();
                }
            }
        }

    }

AnswerRe: Getting 403 (Forbidden) from HttpWebRequest Pin
Keith Barrow20-Aug-13 2:35
professionalKeith Barrow20-Aug-13 2:35 
GeneralRe: Getting 403 (Forbidden) from HttpWebRequest Pin
Member 993503820-Aug-13 3:28
Member 993503820-Aug-13 3:28 
GeneralRe: Getting 403 (Forbidden) from HttpWebRequest Pin
Keith Barrow20-Aug-13 3:56
professionalKeith Barrow20-Aug-13 3:56 
GeneralRe: Getting 403 (Forbidden) from HttpWebRequest Pin
harold aptroot20-Aug-13 4:10
harold aptroot20-Aug-13 4:10 
Questionthreading in c# Pin
Member 1022020019-Aug-13 23:31
Member 1022020019-Aug-13 23:31 
AnswerRe: threading in c# Pin
Pete O'Hanlon20-Aug-13 0:01
mvePete O'Hanlon20-Aug-13 0:01 
SuggestionRe: threading in c# Pin
Ahsan9820-Aug-13 0:20
Ahsan9820-Aug-13 0:20 
SuggestionRe: threading in c# Pin
Ahsan9820-Aug-13 0:31
Ahsan9820-Aug-13 0:31 
GeneralRe: threading in c# Pin
Eddy Vluggen20-Aug-13 0:46
professionalEddy Vluggen20-Aug-13 0:46 
GeneralRe: threading in c# Pin
BillWoodruff20-Aug-13 15:08
professionalBillWoodruff20-Aug-13 15:08 
AnswerRe: threading in c# Pin
Ravi Bhavnani21-Aug-13 7:42
professionalRavi Bhavnani21-Aug-13 7:42 
QuestionWindowsApp and Website Share One Database Pin
ali_heidari_19-Aug-13 23:15
ali_heidari_19-Aug-13 23:15 
AnswerRe: WindowsApp and Website Share One Database Pin
Eddy Vluggen20-Aug-13 0:50
professionalEddy Vluggen20-Aug-13 0:50 
GeneralRe: WindowsApp and Website Share One Database Pin
ali_heidari_21-Aug-13 23:17
ali_heidari_21-Aug-13 23:17 
AnswerRe: WindowsApp and Website Share One Database Pin
SaqibRasheed20-Aug-13 12:37
SaqibRasheed20-Aug-13 12:37 
QuestionRDLC Report Designer Pin
cdpsource19-Aug-13 22:10
cdpsource19-Aug-13 22:10 
QuestionBest way to declaring multiple objects Pin
rfresh19-Aug-13 18:06
rfresh19-Aug-13 18:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.