Skip to main content
gamedev.net
🔒 Locked

Help - can't upload data

Started by Greycrow Apr 8, 2009 at 11:01 AM 1 replies 650+ views
Original Post
Greycrow
Greycrow
I am trying to upload a new high score to my web site here is the code

[Serializable]
    public struct HighScoreData
    {
        public string PlayerName;
        public int Score;
        public int Level;

    }

public HighScoreData data = new HighScoreData();

data.PlayerName = "Me";
data.Score = 15000;
data.Level = 10;

WebClient wc = new WebClient();
string internetURL = "ftp://www.mysite.com/HighScores.xml"; 

XmlSerializer serializer = new XmlSerializer(typeof(HighScoreData));
MemoryStream ms = new MemoryStream();
serializer.Serialize(ms, data);

byte[] bytData = ms.GetBuffer();

wc.Credentials = new NetworkCredential("username", "password");
byte[] response = wc.UploadData(internetURL,"POST", bytData);


The last line throws an exception "An Exception occured during a webclient request" what am I doing wrong here? Grey
hplus0603
hplus0603
What specific exception is being thrown? The type and message of the exception (and any InnerException) will tell you what went wrong.
Also, if you look in the log file on your web server, do you see the request come in?
Oh, and I don't think you can "POST" to a ftp: URL through the WebClient. Try using a http URL instead.
enum Bool { True, False, FileNotFound };
Greycrow
Greycrow
Thanks for the reply.
You were right about the "POST" part.

I just had to change the last line to

byte[] response = wc.UploadData(internetURL,bytData);

and everything works fine

:)

Grey

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.