Skip to content

Commit

Permalink
Added better error handeling on HTTPClient.Post()
Browse files Browse the repository at this point in the history
  • Loading branch information
lieuwex committed Feb 9, 2014
1 parent a501883 commit 4645cd7
Show file tree
Hide file tree
Showing 14 changed files with 9 additions and 2 deletions.
Binary file modified bin/MataSharp.dll
Binary file not shown.
9 changes: 8 additions & 1 deletion src/MataSharp/HTTPClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@ public void Put(string URL, string Data)

public string Post(string URL, NameValueCollection Values)
{
byte[] tmpArr = this.Client.UploadValues(URL, Values);
byte[] tmpArr = null;
try { tmpArr = this.Client.UploadValues(URL, Values); }
catch(WebException e)
{
if (((HttpWebResponse)e.Response).StatusCode == HttpStatusCode.Unauthorized)
throw new System.Security.Authentication.AuthenticationException("Wrong username and/or password.");
else throw e;
}
return stripString(Encoding.ASCII.GetString(tmpArr));
}

Expand Down
Binary file modified src/MataSharp/bin/Release/MataSharp.dll
Binary file not shown.
Binary file modified src/MataSharp/bin/Release/MataSharp.pdb
Binary file not shown.
Binary file modified src/MataSharp/obj/Release/MataSharp.dll
Binary file not shown.
Binary file modified src/MataSharp/obj/Release/MataSharp.pdb
Binary file not shown.
2 changes: 1 addition & 1 deletion src/MataTest/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static void Main(string[] args)
var schools = MagisterSchool.GetSchools(Console.ReadLine());

for (int i = 0; i < schools.Count; i++)
Console.WriteLine(i + ": " + schools[i].Name + " " + schools[i].URL);
Console.WriteLine(i + ": " + schools[i].ToString());

MagisterSchool school = schools[Convert.ToInt32(Console.ReadLine())];
#endregion
Expand Down
Binary file modified src/MataTest/bin/Debug/MataSharp.dll
Binary file not shown.
Binary file modified src/MataTest/bin/Debug/MataSharp.pdb
Binary file not shown.
Binary file modified src/MataTest/bin/Debug/MataTest.exe
Binary file not shown.
Binary file modified src/MataTest/bin/Debug/MataTest.pdb
Binary file not shown.
Binary file not shown.
Binary file modified src/MataTest/obj/Debug/MataTest.exe
Binary file not shown.
Binary file modified src/MataTest/obj/Debug/MataTest.pdb
Binary file not shown.

0 comments on commit 4645cd7

Please sign in to comment.