2010-11-29 4 views
1

내 개발 기계 (XP)에서 WebRequest.GetResponse()를 사용했는데 제대로 작동하고 URL에서 응답 스트림을 읽을 수 있지만 컴파일 된 URL이 동일한 경우 두 클라이언트 컴퓨터 (Windows 7)에서 코드가 실패합니다. WebException.Status는 "네트워크 요청이 지원되지 않습니다."입니다. 같은 URL에 액세스하려고 시도하는 이유는 무엇입니까? WebException은 GetResponse 메서드에 의해 시작됩니다. catch 절에서 응답 객체와 WebException.Response 객체는 모두 null입니다. 문제를 더 진단하려면 어떻게해야합니까?Webrequest.GetResponse()는 클라이언트 컴퓨터가 아닌 개발 컴퓨터에서 작동합니다.

WebRequest request = null; 
HttpWebResponse response = null; 
Stream dataStream = null; 
StreamReader reader = null; 
String responseFromServer = string.Empty; 
string http = string.Empty; 
int timeOut = 30000; 
string errorMsg = string.Empty; 
http = this.URLstring; 
bool error = false; 

try 
{ 
    request = System.Net.WebRequest.Create(http); 
    request.Timeout = timeOut; 
    response = (System.Net.HttpWebResponse)request.GetResponse(); 
} 
catch (System.Net.WebException wex) 
{ 
    error = true; 
    errorMsg = wex.Message + " " + wex.Status.ToString(); 

    if (wex.Response != null) 
    { 
     WebHeaderCollection hdrs = wex.Response.Headers; 

     for (int i = 0; i < hdrs.Count; i++) 
      errorMsg += Environment.NewLine + hdrs.Keys[i] + ", " + hdrs[i]; 
    } 
} 

// Code to read the response stream goes here. it works on development machine. 
+2

코드를 들여 쓰기하십시오. 읽기가 훨씬 쉬워요. –

+0

키워드 사용을 사용하는 것이 좋습니다. –

+0

(전체) Errormessage 텍스트를 게시하면 도움이 될 수도 있습니다. –

답변

2

권한 문제 일 수 있습니다. 테스트하려면 Win7 '관리자 권한으로 앱을 실행하십시오.

관련 문제