mardi 31 mars 2015

C# HttpRequest: Not found error

I have this code:



HttpWebRequest spAuthReq = HttpWebRequest.Create(new Uri(myURL, UriKind.RelativeOrAbsolute)) as HttpWebRequest;
spAuthReq.Method = "GET";
spAuthReq.BeginGetResponse(new AsyncCallback(GetResponsetStreamCallback), spAuthReq);

void GetResponsetStreamCallback(IAsyncResult callbackResult)
{
try
{
HttpWebRequest request = (HttpWebRequest)callbackResult.AsyncState;
HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(callbackResult);
Stream streamResponse = response.GetResponseStream();
StreamReader reader = new StreamReader(streamResponse);
responseString = reader.ReadToEnd();
streamResponse.Close();
reader.Close();
response.Close();
string result = responseString;
}
catch (WebException ex)
{
responseString = ex.ToString();
}
}


I need to get some messages but I get error: System.Net.WebException: The remote server returned an error: NotFound. Also I need to post token to server because it requies login, I have token but I don't know how to post token with GET method. Anyway, without token I should get response from server that I'm not logged in but I end up with exception.





Aucun commentaire:

Enregistrer un commentaire