1

私は、Fusemail を asp.net 2.0 に統合するつもりです。API ページのリクエストに HttpWebRequest を使用しています。最近、HttpWebRequest が最初に失敗し、その後継続して後続の要求が成功することに気づきました。

もし私がこのコードを使ったら

retry:
        try
        {
            Uri uri = new Uri("http://www.fusemail.com/api/request.html");
            if (uri.Scheme == Uri.UriSchemeHttp)
            {

                HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
                request.PreAuthenticate = true;
                request.Method =
                WebRequestMethods.Http.Post;

                //request.ReadWriteTimeout = System.Threading.Timeout.Infinite;
                //request.Timeout = System.Threading.Timeout.Infinite;
                request.ContentLength = data.Length;
                request.ContentType =
                "application/x-www-form-urlencoded";
                //request.UserAgent = Request.UserAgent;
                request.UserAgent = "Mozilla/4.0";
                request.KeepAlive = false;

                request.ServicePoint.Expect100Continue = true;
                //request.Accept = "Accept: text/html,application/xhtml+xml,application/xml";


                StreamWriter writer = new StreamWriter(request.GetRequestStream());
                writer.Write(data);
                writer.Close();

                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                StreamReader reader = new StreamReader(response.GetResponseStream());
                string tmp = reader.ReadToEnd();
                response.Close();
                //Response.Write(tmp);

                if (!String.IsNullOrEmpty(tmp))
                {
                    return tmp;
                }
            }
            return String.Empty;
        }
        catch (WebException ex)
        {

            goto retry;
        }

一度失敗した後に動作します。エラーが発生した場合に備えてテキストファイルに書き込んでいますが、リクエストに失敗した後、2回目に機能します。ASP.Net 2.0 を使用しており、Web サイトは Windows Server 2008 Standard の IIS 7 でホストされています。また、APIアドレスにpingを実行すると、最初は失敗してから応答します

C:\>ping 67.207.202.118

Pinging 67.207.202.118 with 32 bytes of data:
Reply from 192.168.0.253: **Destination host unreachable**.
Reply from 67.207.202.118: bytes=32 time=218ms TTL=49
Reply from 67.207.202.118: bytes=32 time=218ms TTL=49
Reply from 67.207.202.118: bytes=32 time=217ms TTL=49

Ping statistics for 67.207.202.118:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 217ms, Maximum = 218ms, Average = 217ms

HttpWebRequest で初めて失敗すると、このエラーで失敗します

System.Net.WebException: リモート サーバーに接続できません ---> System.Net.Sockets.SocketException: 接続先が一定時間後に適切に応答しなかったため、接続の試行が失敗したか、接続されたホストが原因で確立された接続が失敗しました67.207.202.118:80 に応答できませんでした

初めて認証の問題はありますか? いくつかのフォーラムで、最初に 401 Unauthorized を送信してから接続できると読みました。Fiddler を使用してこれを確認できません。

IIS の構成に何か問題がありますか?

4

2 に答える 2

1

This is not a programming issue at all, I have faced a similar problem later and it was a network configuration problem due to ISA server / Firewall settings. You have to contact your network administrator to check this issue.

I wish this helped you.

Yours,

Mohamed Kamal Elbeah

Senior .Net Developer

于 2011-04-17T15:01:47.917 に答える