2011-09-28 4 views
0

때때로 일부 컴퓨터에서는 웹 요청이 다음 메시지와 함께 실패하고 프로그램을 다시 설정할 때까지 계속 작업을 다시 시작합니다. 다른 사람이 이것을 경험 했습니까? 그리고 그것을 방지하기위한 프로그래밍 방식이 있습니까?HttpWebRequest.GetResponse가 프로그램 재설정까지 계속 실패 함

Message: The remote name could not be resolved: 'www.validwebsite.com' Source: System StackTrace: at System.Net.HttpWebRequest.GetResponse()

편집 :이 코드 인 그

virtual public string Execute(string web_uri,string request_method,string data = null, string content_type = null) 
    { 
     WebRequest webRequest = WebRequest.Create(web_uri); 
     webRequest.Method = request_method; 
     if (content_type != null) 
     { 
      webRequest.ContentType = content_type; 
     } 
     webRequest.Method = request_method; 
     byte[] bytes = new byte[0]; 
     if (!string.IsNullOrEmpty(data)) 
     { 
      bytes = Encoding.ASCII.GetBytes(data); 
      // send the Post 
      webRequest.ContentLength = bytes.Length; //Count bytes to send 
     } 
     else 
     { 
      webRequest.ContentLength = 0; 
     } 
     if (webRequest.Method == "POST") 
     { 
      using (Stream os = webRequest.GetRequestStream()) 
      { 
       os.Write(bytes, 0, bytes.Length);   //Send it 
      } 
     } 
     using (HttpWebResponse webResponse =(HttpWebResponse)webRequest.GetResponse()) 
     { 
      if (webResponse != null) 
      { 
       ResponseCode = webResponse.StatusCode; 
       using (StreamReader sr = new StreamReader(webResponse.GetResponseStream(),Encoding.UTF8)) 
       { 
        string xml_string = sr.ReadToEnd().Trim(); 
        return xml_string; 
       } 
      } 
     } 
     return null; 
+0

관련 소스 코드를 표시하십시오! – Yahia

+0

프록시 서버를 사용합니까? – CodeCaster

+0

@CodeCaster -이 컴퓨터에서 프록시가 사용되고 있지만 응용 프로그램 구성 파일에는 일반적으로 원격 웹 사이트에 액세스 할 수 있도록 가 포함되어 있습니다. –

답변

1

은 DNS 문제를 배제하기 위해 호스트 파일에 항목을 넣어 실행되고있다. 그런 다음 앱이 일관되게 작동하면 문제를 발견했습니다.

관련 문제