zoukankan      html  css  js  c++  java
  • HttpWebRequest: Remote server returns error 503 Server Unavailable

     

    I have a client server application written in C# .Net 2.0. I have had the client/server response/request code running for 4 years(!). Recently, on a specific machine, the client can not connect to server:

    on the code line:

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

    WebException: The remote server returned an error: (503) Server Unavailable.
    Message="The remote server returned an error: (503) Server Unavailable."
    Status System.Net.WebExceptionStatus.ProtocolError

    I believe this issue is machine-specific since i never had this issue on any other machine.

    Is there something I need to configure on that machine? What did I miss?

    HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(string.Format("http://{0}:{1}/", server, httpPort));

    request.ContentType = "application/x-www-form-urlencoded";

    string msgStr = msgString;

    byte[] buffer = Encoding.UTF8.GetBytes(msgStr);

    request.ContentLength = buffer.Length;

    request.Method = "POST";

     

    try {

    System.IO.Stream requestStream = request.GetRequestStream();

    requestStream.Write(buffer, 0, buffer.Length);

    requestStream.Close();

    requestStream.Dispose();

     

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

     

    byte[] inBuffer = new byte[10000];

    Stream responseStream = response.GetResponseStream();

    int iBytes = responseStream.Read(inBuffer, 0, inBuffer.Length);

     

    StringBuilder sb = new StringBuilder(10000);

     

    while (iBytes > 0) {

    sb.Append(Encoding.UTF8.GetString(inBuffer, 0, iBytes));

    iBytes = responseStream.Read(inBuffer, 0, inBuffer.Length);

    }

     

    response.Close();

    responseStream.Close();

    responseStream.Dispose();

     

    if (!string.IsNullOrEmpty(sb.ToString())) {

    message = HandleMessage(sb.ToString());

    } else { //bug 58

    message = HandleEmptyMessage(msgString);

    }

    } catch (System.Net.WebException we) {

    _connected = false;

    EventsHelper.AsyncFire(ConnectionLost, this, EventArgs.Empty);

    throw new Exception(we.Message);

    }

     

    [Answers 1]


    If it is only one machine it is probably environmental. It could be a DNS issue, a firewall issue, a router issue, an ISP issue

     

    [Answers 2]


    Thanks Jared! it was indeed a wrong network configuration.

     

     

    From: https://stackoverflow.com/questions/14504165/remote-server-returns-error-503-server-unavailable

     

     

     

  • 相关阅读:
    luogu 1169 棋盘制作(单调栈/悬线)
    poj 2769 感觉♂良好 (单调栈)
    hdu 5033 buiding(单调栈)
    hdu1506 直方图中最大的矩形 单调栈入门
    有线电视网(树形dp)
    洛谷P1220 关路灯(区间dp)
    【题解】NOI2009二叉查找树 + NOIP2003加分二叉树
    【题解】AHOI2009中国象棋
    【算法】Matrix
    【题解】WC2008游览计划
  • 原文地址:https://www.cnblogs.com/time-is-life/p/8038220.html
Copyright © 2011-2022 走看看