私はURLを呼び出し、そのサービスによって書き込まれたステータスをキャプチャする非常に簡単なサービスを持っています。 myServiceURLラインの基底の接続が閉じられました:予期しないエラーが発生しました
// Service call used to determine availability
System.Net.WebClient client = new System.Net.WebClient();
// I need this one (sorry, cannot disclose the actual URL)
Console.WriteLine(client.DownloadString(myServiceURL + ";ping"));
// I added this for test purposes
Console.WriteLine(client.DownloadString("https://www.google.com"));
「DownloadStringは、」「基になる接続が閉じられました:予期しないエラーが発生しました」エラーをスローし、google.comのための「DownloadStringは」作品のに対し示すものは、この行のためにフィドラーでありませんし、私はそのためのコンソール出力を参照してください。
エラーの別の提案に続いて、UseDefaultCredentials、エンコーディングオプションの設定、適切なヘッダーのリクエストへの追加を試みましたが、いずれも違いはありません。
client.UseDefaultCredentials = true;
client.Encoding = Encoding.UTF8;
ブラウザでmyServiceURLに移動すると、正常に動作し、「OK」と表示されます。次のように
同じサービスからもう一つの方法は、符号化されている:
// Request
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(myServiceURL + ";login");
// Set the request configuration options
req.Method = "POST";
req.ContentType = "text/xml";
req.ContentLength = bytes.Length;
req.Timeout = -1;
// Call for the request stream
using (Stream os = req.GetRequestStream())
{
os.Write(bytes, 0, bytes.Length);
}
// ....snip
// This line fails with the same error as before
WebResponse resp = req.GetResponse()
この
は、すべての.NET Framework 4.0を使用して、Windows 7(64ビット)PC上で実行されています。 myServiceURLのサービスは、私が制御できない第三者サービスです。
あなたはreq.Proxy = WebProxy.GetDefaultProxy()を試してみましたか? –
GetDefaultProxy(廃止されましたか?)を使用しようとしましたが、違いはありませんでした。 – Sean
ああ申し訳ありませんが、コンテンツタイプではなく、このreqをHttpWebRequest.Accept = "text/xml"として使用できます。 –