Jak naprawić System.ArgumentException w HttpWebResponse?
Stoję przed tym wyjątkiem podczas odbieraniaHttpWebResponse
dla mnieWindowsPhone
aplikacja Jak mam to naprawić. Zdarza się to bardzo często, ale muszę się upewnić, że moja aplikacja nie ulegnie awarii, jeśli tak się stanie. Proszę spojrzeć nazrzut ekranu.
Moja oczekiwana odpowiedź jest
Headers:-
HTTP/1.1 500 Internal Server Error
Date: Wed, 28 Nov 2012 06:41:24 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
Keep-Alive: timeout=30
Set-Cookie: ...........; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Internal Server Error:
Json:-
{"status":0,"error_code":1001,"data":{"msg":"Something went wrong. Please try again later. [error code 1001]"}}
Pokazuje także wInnerException
wiadomość jakoSpecified value has invalid HTTP Header characters. Parameter name: name
Proszę pomóż. Nie wiem, dlaczego webRequest.EndGetResponse (asynchronousResult) nie jest w stanie odczytać odpowiedzi. Czy istnieje alternatywa?
AKTUALIZACJA aby rozpocząć żądanie:
_webRequest.BeginGetRequestStream(new AsyncCallback(GetReqeustStreamCallback), _webRequest);
private void GetReqeustStreamCallback(IAsyncResult asynchronousResult)
{
if ((!ReqIdEnabled || Network.RequestUniqueId == this.RequestUniqueId))
{
HttpWebRequest webRequest = (HttpWebRequest)asynchronousResult.AsyncState;
// End the stream request operation
using (Stream postStream = webRequest.EndGetRequestStream(asynchronousResult))
{
// Add the post data to the web request
postStream.Write(_postDataInBytes, 0, _postDataInBytes.Length);
//postStream.Dispose();
}
// Start the web request
webRequest.BeginGetResponse(new AsyncCallback(GetResponseCallback), webRequest);
}
}
private void GetResponseCallback(IAsyncResult asynchronousResult)
{
HttpWebRequest webRequest = (HttpWebRequest)asynchronousResult.AsyncState;
try
{
//**throws Exception here when my server returns 503/500 and is not caught by the catch block below**
using (HttpWebResponse response = (HttpWebResponse)webRequest.EndGetResponse(asynchronousResult))
{
ReadResponse(response);
}
}
catch (WebException ee)
{
}
}