I have created a class within my PCL to get the needed Session-Id and a Key for login into a webserver. (The response is XML, which is parsed in a second method which runs the Login) I have no control on the WebServer, so I need to solve my problem on the client side.
This is my Task Method:
public static async Task<string> SessionId()
{
HttpWebRequest SessiondIdRequest = (HttpWebRequest)WebRequest.Create(Constants.SessionIdUrl);
SessiondIdRequest.Method = "POST";
SessiondIdRequest.Accept = "application/xml";
SessiondIdRequest.Headers[HttpRequestHeader.AcceptLanguage] = "de-de,de;q=0.8,en-us;q=0.5,en;q=0.3";
SessiondIdRequest.ContentType = "application/x-www-form-urlencoded ";
string appIDviaPOST = "{Here is a String}";
byte[] byteArray = Encoding.UTF8.GetBytes(appIDviaPOST);
using (var SessionIdRequestStream = await Task<Stream>.Factory.FromAsync
(SessiondIdRequest.BeginGetRequestStream, SessiondIdRequest.EndGetRequestStream, SessiondIdRequest))
{
await SessionIdRequestStream.WriteAsync(byteArray, 0, byteArray.Length);
}
WebResponse SessionIdRequestResponse = await Task<WebResponse>.Factory.FromAsync
(SessiondIdRequest.BeginGetResponse, SessiondIdRequest.EndGetResponse, SessiondIdRequest);
var SessionIdRequestResponseStream = SessionIdRequestResponse.GetResponseStream();
var sr = new StreamReader(SessionIdRequestResponseStream);
string SessionIdResult = await sr.ReadToEndAsync();
return SessionIdResult;
}
The Task works very well on WP7 & WP8. I am getting a totally different result when I am using this Method in the Windows 8 part of my app.
I used Fiddler to find out the differences between the two, the most markable thing I saw that WP7&8 are using HTTP 1.0 and send an UserAgent, whereas Win8 uses HTTP 1.1 and does not send an UserAgent.
In PCL, the HttpWebRequest does not contain properties for UserAgent and ProtocolVersion, so I am not able to tell the Method to force it (because it is a subset only).
Is there any way to work around this (besides to copy the whole method into my Win8 project, where I am able to set those properties).
I am very new to MVVM and PCL, so please be a bit forgiving it this is a dumb question for you. Thanks.