I tried to mke a request with GET and parameters. However, I got an exception for the WinPhone8.1 which meaned that GET was a violation protocol due to a content added in. So making a POST request is the solution.
Despite my searches, I'm still not able to set the content lenght property of my HttpWebRequest.. Why?
private static async void AsyncRequest(string url, string contentType, string methodType, int contentLenght, Action<Object, string> callback, Action<HttpStatusCode, JObject, Action<Object, string>> parserFunction)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.ContentType = contentType;
request.Method = methodType;
request.Proxy = null;
if (methodType == Method.POST)
{
request.ContentLenght = "contentLenght";
request.Headers["content-length"] = "contentLenght";
request.Headers["Content-Length"] = "contentLenght";
request.Headers[HttpRequestHeader.ContentLength] = "contentLenght";
request.Headers["HttpRequestHeader.ContentLength"] = "contentLenght";
request.Content.Headers.ContentLength = "contentLenght";
...........
Nothing works ><
}
Debug.WriteLine("1");
Task<WebResponse> task = Task.Factory.FromAsync(
request.BeginGetResponse,
asyncResult => request.EndGetResponse(asyncResult),
(object)null);
Debug.WriteLine("2");
await task.ContinueWith(t => ReadStreamFromResponse(t.Result, callback, parserFunction));
}
"contentLenght"
? Should it not be a long value instead of string? @Yolandayolande – Incurrent